Skip to content
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

initial Migration to cucumber 7 #456

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ DS_Store
bin/
io.cucumber.eclipse.lsp/
cucumber.*/
.polyglot*
.polyglot*
/.project
.settings/
2 changes: 1 addition & 1 deletion io.cucumber.eclipse.editor/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Require-Bundle: org.eclipse.ui;bundle-version="3.5.0",
org.apache.commons.commons-text;bundle-version="1.9.0",
org.apache.commons.io;bundle-version="2.6.0",
io.cucumber.tag-expressions,
org.eclipse.unittest.ui;bundle-version="1.0.0"
org.eclipse.unittest.ui
Bundle-RequiredExecutionEnvironment: JavaSE-11
Automatic-Module-Name: io.cucumber.eclipse.editor
Bundle-ActivationPolicy: lazy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
import io.cucumber.eclipse.editor.document.GherkinEditorDocument;
import io.cucumber.eclipse.editor.launching.ILauncher;
import io.cucumber.eclipse.editor.launching.ILauncher.Mode;
import io.cucumber.messages.Messages.GherkinDocument.Feature;
import io.cucumber.messages.Messages.GherkinDocument.Feature.Scenario;
import io.cucumber.messages.Messages.GherkinDocument.Feature.Tag;
import io.cucumber.messages.Messages.Location;
import io.cucumber.messages.types.Feature;
import io.cucumber.messages.types.Location;
import io.cucumber.messages.types.Scenario;
import io.cucumber.messages.types.Tag;
import io.cucumber.tagexpressions.TagExpressionParser;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import io.cucumber.eclipse.editor.document.GherkinEditorDocument;
import io.cucumber.eclipse.editor.document.GherkinKeyword;
import io.cucumber.gherkin.GherkinDialect;
import io.cucumber.messages.Messages.GherkinDocument.Feature;
import io.cucumber.messages.Messages.GherkinDocument.Feature.FeatureChild;
import io.cucumber.messages.types.Feature;
import io.cucumber.messages.types.FeatureChild;

/**
* Provides content assist for gherkin keywords
Expand Down Expand Up @@ -53,9 +53,9 @@ public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int
.map(featureKeyWord -> createFeatureKeyWordProposal(featureKeyWord.getKey(), offset, typed))
.toArray(ICompletionProposal[]::new);
}
Predicate<FeatureChild> hasTopLevelElement = FeatureChild::hasBackground;
hasTopLevelElement = hasTopLevelElement.or(FeatureChild::hasRule);
hasTopLevelElement = hasTopLevelElement.or(FeatureChild::hasScenario);
Predicate<FeatureChild> hasTopLevelElement = f->f.getBackground().isPresent();
hasTopLevelElement = hasTopLevelElement.or(f->f.getRule().isPresent());
hasTopLevelElement = hasTopLevelElement.or(f->f.getScenario().isPresent());
if (editorDocument.getFeatureChilds().filter(hasTopLevelElement).count() == 0) {
// in this case Rule, Scenario or background are required
return editorDocument.getTopLevelKeywords()//
Expand Down Expand Up @@ -102,7 +102,7 @@ public IContextInformation[] computeContextInformation(ITextViewer viewer, int o
try {
IRegion line = viewer.getDocument().getLineInformationOfOffset(offset);

String typed = viewer.getDocument().get(line.getOffset(), offset - line.getOffset()).stripLeading();
/* String typed = */ viewer.getDocument().get(line.getOffset(), offset - line.getOffset()).stripLeading();

editorDocument.keyWords(GherkinDialect::getFeatureKeywords);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IDebugElement;

import io.cucumber.messages.Messages.TestCase.TestStep.StepMatchArgumentsList.StepMatchArgument.Group;
import io.cucumber.messages.types.Group;

/**
* A group value
Expand All @@ -22,7 +22,7 @@ public GherkingGroupValue(IDebugElement parent, String type, Group group) {

@Override
public String getValueString() throws DebugException {
return group.getValue();
return group.getValue().orElse(null);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public GherkingStackFrame(IThread thread, int lineNumber, String name) {
this.name = name;
}



@Override
public boolean canStepInto() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IDebugElement;

import io.cucumber.messages.Messages.StepDefinition;
import io.cucumber.messages.types.StepDefinition;

/**
* A value representing a step definition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import org.eclipse.debug.core.model.IThread;
import org.eclipse.debug.core.model.IVariable;

import io.cucumber.messages.Messages.GherkinDocument.Feature.Step;
import io.cucumber.messages.Messages.StepDefinition;
import io.cucumber.messages.Messages.TestCase.TestStep;
import io.cucumber.messages.types.Step;
import io.cucumber.messages.types.StepDefinition;
import io.cucumber.messages.types.TestStep;

/**
* Special stackframe that represents a test-step
Expand All @@ -25,7 +25,7 @@ public class GherkingStepStackFrame extends GherkingStackFrame {
private DebugRunnable stepOverHandler;

public GherkingStepStackFrame(IThread thread, TestStep testStep, Step step, StepDefinition stepDefinition) {
super(thread, step.getLocation().getLine(), "[" + step.getKeyword().strip() + "] " + step.getText());
super(thread, step.getLocation().getLine().intValue(), "[" + step.getKeyword().strip() + "] " + step.getText());
this.testStep = testStep;
this.step = step;
this.stepDefinition = stepDefinition;
Expand All @@ -41,11 +41,12 @@ public GherkingStepStackFrame(IThread thread, TestStep testStep, Step step, Step

private void addGroups(GherkingStackFrame stepFrame, Consumer<IVariable> variableConsumer) {
AtomicInteger counter = new AtomicInteger();
testStep.getStepMatchArgumentsListsList().stream().flatMap(list -> list.getStepMatchArgumentsList().stream())
testStep.getStepMatchArgumentsLists().stream().flatMap(list -> list.stream().flatMap(p->p.getStepMatchArguments().stream()))
.forEach(argument -> {
String type = argument.getParameterTypeName();
variableConsumer.accept(new GherkingStepVariable(stepFrame, "arg" + counter.get(),
new GherkingGroupValue(stepFrame.getDebugTarget(), type, argument.getGroup())));
argument.getParameterTypeName().ifPresent(type->
variableConsumer.accept(new GherkingStepVariable(stepFrame, "arg" + counter.get(),
new GherkingGroupValue(stepFrame.getDebugTarget(), type, argument.getGroup())))
);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import org.osgi.service.component.annotations.Component;

import io.cucumber.eclipse.editor.document.GherkinEditorDocument;
import io.cucumber.messages.Messages.GherkinDocument.Feature.Step;
import io.cucumber.messages.Messages.Location;
import io.cucumber.messages.types.Step;
import io.cucumber.messages.types.Location;

/**
* Service for providing breakpoints to the generic editor
Expand Down Expand Up @@ -102,7 +102,7 @@ public boolean canToggleBreakpoints(IWorkbenchPart part, ISelection selection) {
ITextSelection textSelection = (ITextSelection) selection;
int lineNumber = textSelection.getStartLine() + 1;
Stream<Location> stream = editorDocument.getSteps().map(Step::getLocation);
return stream.mapToInt(Location::getLine).filter(line -> line == lineNumber).findAny().isPresent();
return stream.mapToLong(Location::getLine).filter(line -> line == lineNumber).findAny().isPresent();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.Position;

import io.cucumber.gherkin.Gherkin;
//import io.cucumber.gherkin.Gherkin;
import io.cucumber.gherkin.GherkinDialect;
import io.cucumber.gherkin.GherkinDialectProvider;
import io.cucumber.gherkin.Location;
import io.cucumber.gherkin.ParserException.NoSuchLanguageException;
import io.cucumber.gherkin.GherkinParser;
import io.cucumber.messages.IdGenerator;
import io.cucumber.messages.Messages.Envelope;
import io.cucumber.messages.types.Attachment;
import io.cucumber.messages.types.Envelope;
import io.cucumber.messages.types.Source;
import io.cucumber.messages.types.SourceMediaType;

/**
*
Expand Down Expand Up @@ -70,8 +72,8 @@ public final class GherkinEditorDocument extends GherkinStream {
private Supplier<IResource> resourceSupplier;

private GherkinEditorDocument(IDocument document, Supplier<IResource> resourceSupplier) {
super(Gherkin.fromSources(Collections.singletonList(Gherkin.makeSourceEnvelope(document.get(), "")), true, true,
false, new IdGenerator.Incrementing()).toArray(Envelope[]::new));

super(getEnvelopes(document, resourceSupplier));
this.resourceSupplier = resourceSupplier;
document.addDocumentListener(new IDocumentListener() {

Expand All @@ -87,28 +89,46 @@ public void documentAboutToBeChanged(DocumentEvent event) {
}
});
this.document = document;
dialect = getFeature().map(f -> f.getLanguage()).filter(Objects::nonNull).filter(Predicate.not(String::isBlank))
.map(lang -> provider.getDialect(lang, new Location(-1, -1))).orElseGet(() -> {
try {
IRegion firstLine = document.getLineInformation(0);
String line = document.get(firstLine.getOffset(), firstLine.getLength()).trim();
if (line.startsWith("#")) {
String[] split = line.split("language:", 2);
if (split.length == 2) {
try {
return provider.getDialect(split[1].trim(), new Location(-1, -1));
} catch (NoSuchLanguageException e) {
}
}

Optional<String> langOpt = getFeature().map(f -> f.getLanguage()).filter(Objects::nonNull)
.filter(Predicate.not(String::isBlank));

dialect = langOpt.map(lang -> provider.getDialect(lang, null)).orElseGet(() -> {
try {
IRegion firstLine = document.getLineInformation(0);
String line = document.get(firstLine.getOffset(), firstLine.getLength()).trim();
if (line.startsWith("#")) {
String[] split = line.split("language:", 2);
if (split.length == 2) {
try {
return provider.getDialect(split[1].trim(), null);
} catch (Exception e) {
}
} catch (BadLocationException e) {
}
return provider.getDefaultDialect();
});

}
} catch (BadLocationException e) {
}
return provider.getDefaultDialect();
});

locale = Locale.forLanguageTag(dialect.getLanguage());

}

private static Envelope[] getEnvelopes(IDocument document, Supplier<IResource> resourceSupplier) {
// Gherkin.fromSources(Collections.singletonList(Gherkin.makeSourceEnvelope(document.get(), "")), true, true,
// false, new IdGenerator.Incrementing()).toArray(Envelope[]::new)
GherkinParser parser = GherkinParser.builder()
.includeSource(true)
.includeGherkinDocument(true)
.includePickles(false)
.build();
Source source = new Source("", document.get(), SourceMediaType.TEXT_X_CUCUMBER_GHERKIN_PLAIN);
Envelope envelope = Envelope.of(source);
return parser.parse(envelope).toArray(Envelope[]::new);
}

/**
* @return the dialect of the document
*/
Expand All @@ -127,19 +147,19 @@ public IDocument getDocument() {
return document;
}

public Position getPosition(io.cucumber.messages.Messages.Location location) throws BadLocationException {
public Position getPosition(io.cucumber.messages.types.Location location) throws BadLocationException {
return getPosition(location, 0);
}

public Position getPosition(io.cucumber.messages.Messages.Location location, int lineOffset)
public Position getPosition(io.cucumber.messages.types.Location location, int lineOffset)
throws BadLocationException {
int line = location.getLine();
int line = location.getLine().intValue();
int offset = document.getLineOffset(line - 1 - lineOffset);
return new Position(offset + location.getColumn() - 1, 1);
return new Position(offset + location.getColumn().orElse(0l).intValue() - 1, 1);
}

public Position getEolPosition(io.cucumber.messages.Messages.Location location) throws BadLocationException {
int line = location.getLine();
public Position getEolPosition(io.cucumber.messages.types.Location location) throws BadLocationException {
int line = location.getLine().intValue();
int offset = document.getLineOffset(line - 1);
int lineLength = document.getLineLength(line - 1);
// Workaround for Bug 570740
Expand Down
Loading