From 0b0cfc3cb4e4c929211c8f1932e35db9edd00c58 Mon Sep 17 00:00:00 2001 From: Nicholas DiPiazza Date: Fri, 5 Jun 2020 13:52:04 -0500 Subject: [PATCH 1/3] fix step hyperlink detector for multi-project setup when doing the StepHyperlinkDetector, expand to fetch from all projects, not just the one the gherkin file is from. --- .../editor/editors/jumpto/StepHyperlinkDetector.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cucumber.eclipse.editor/src/main/java/cucumber/eclipse/editor/editors/jumpto/StepHyperlinkDetector.java b/cucumber.eclipse.editor/src/main/java/cucumber/eclipse/editor/editors/jumpto/StepHyperlinkDetector.java index 4e510462..c6b49b1c 100644 --- a/cucumber.eclipse.editor/src/main/java/cucumber/eclipse/editor/editors/jumpto/StepHyperlinkDetector.java +++ b/cucumber.eclipse.editor/src/main/java/cucumber/eclipse/editor/editors/jumpto/StepHyperlinkDetector.java @@ -1,9 +1,11 @@ package cucumber.eclipse.editor.editors.jumpto; +import java.util.HashSet; import java.util.Set; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; @@ -59,9 +61,12 @@ public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boo .getAttribute(MarkerFactory.STEP_DEFINITION_MATCH_JDT_HANDLE_IDENTIFIER_ATTRIBUTE); //Search step in repository if (id != null) { - StepDefinitionsRepository repository = StepDefinitionsStorage.INSTANCE - .getOrCreate(gherkinFile.getProject(), null); - Set stepDefinitions = repository.getAllStepDefinitions(); + Set stepDefinitions = new HashSet<>(); + for (IProject project : gherkinFile.getProject().getWorkspace().getRoot().getProjects()) { + StepDefinitionsRepository repository = StepDefinitionsStorage.INSTANCE + .getOrCreate(project, null); + stepDefinitions.addAll(repository.getAllStepDefinitions()); + } for (StepDefinition stepDefinition : stepDefinitions) { if (id.equals(stepDefinition.getId())) { // define the hyperlink region From ae328dc9cc322b73ac5465fce5249e289e0ac544 Mon Sep 17 00:00:00 2001 From: Nicholas DiPiazza Date: Fri, 5 Jun 2020 14:02:55 -0500 Subject: [PATCH 2/3] do the same for jump to step definition as well --- .../editor/editors/jumpto/JumpToStepDefinition.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cucumber.eclipse.editor/src/main/java/cucumber/eclipse/editor/editors/jumpto/JumpToStepDefinition.java b/cucumber.eclipse.editor/src/main/java/cucumber/eclipse/editor/editors/jumpto/JumpToStepDefinition.java index 507dbb01..e943c44d 100644 --- a/cucumber.eclipse.editor/src/main/java/cucumber/eclipse/editor/editors/jumpto/JumpToStepDefinition.java +++ b/cucumber.eclipse.editor/src/main/java/cucumber/eclipse/editor/editors/jumpto/JumpToStepDefinition.java @@ -1,10 +1,12 @@ package cucumber.eclipse.editor.editors.jumpto; +import java.util.HashSet; import java.util.List; import java.util.Set; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; @@ -29,9 +31,12 @@ public static StepDefinition findStepDefinitionMatch(int selectionLineNumber, IF .getAttribute(MarkerFactory.STEP_DEFINITION_MATCH_JDT_HANDLE_IDENTIFIER_ATTRIBUTE); //Search step in repository if (id != null) { - StepDefinitionsRepository repository = StepDefinitionsStorage.INSTANCE - .getOrCreate(gherkinFile.getProject(), null); - Set stepDefinitions = repository.getAllStepDefinitions(); + Set stepDefinitions = new HashSet<>(); + for (IProject project : gherkinFile.getProject().getWorkspace().getRoot().getProjects()) { + StepDefinitionsRepository repository = StepDefinitionsStorage.INSTANCE + .getOrCreate(project, null); + stepDefinitions.addAll(repository.getAllStepDefinitions()); + } for (StepDefinition step : stepDefinitions) { if (id.equals(step.getId())) { return step; From 2e05a30d6e7822166a5a2a3f4b6066f49a853c34 Mon Sep 17 00:00:00 2001 From: Nicholas DiPiazza Date: Fri, 5 Jun 2020 14:48:13 -0500 Subject: [PATCH 3/3] better error handling when checking projects don't look for stepdefs in closed projects and ignore failures when trying in case something unexpected happens. --- .../editor/editors/jumpto/JumpToStepDefinition.java | 12 +++++++++--- .../editor/editors/jumpto/StepHyperlinkDetector.java | 12 +++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/cucumber.eclipse.editor/src/main/java/cucumber/eclipse/editor/editors/jumpto/JumpToStepDefinition.java b/cucumber.eclipse.editor/src/main/java/cucumber/eclipse/editor/editors/jumpto/JumpToStepDefinition.java index e943c44d..b8b0ebc7 100644 --- a/cucumber.eclipse.editor/src/main/java/cucumber/eclipse/editor/editors/jumpto/JumpToStepDefinition.java +++ b/cucumber.eclipse.editor/src/main/java/cucumber/eclipse/editor/editors/jumpto/JumpToStepDefinition.java @@ -33,9 +33,15 @@ public static StepDefinition findStepDefinitionMatch(int selectionLineNumber, IF if (id != null) { Set stepDefinitions = new HashSet<>(); for (IProject project : gherkinFile.getProject().getWorkspace().getRoot().getProjects()) { - StepDefinitionsRepository repository = StepDefinitionsStorage.INSTANCE - .getOrCreate(project, null); - stepDefinitions.addAll(repository.getAllStepDefinitions()); + try { + if (project.isOpen()) { + StepDefinitionsRepository repository = StepDefinitionsStorage.INSTANCE + .getOrCreate(project, null); + stepDefinitions.addAll(repository.getAllStepDefinitions()); + } + } catch (Exception e) { + e.printStackTrace(); + } } for (StepDefinition step : stepDefinitions) { if (id.equals(step.getId())) { diff --git a/cucumber.eclipse.editor/src/main/java/cucumber/eclipse/editor/editors/jumpto/StepHyperlinkDetector.java b/cucumber.eclipse.editor/src/main/java/cucumber/eclipse/editor/editors/jumpto/StepHyperlinkDetector.java index c6b49b1c..4bc1a4e6 100644 --- a/cucumber.eclipse.editor/src/main/java/cucumber/eclipse/editor/editors/jumpto/StepHyperlinkDetector.java +++ b/cucumber.eclipse.editor/src/main/java/cucumber/eclipse/editor/editors/jumpto/StepHyperlinkDetector.java @@ -63,9 +63,15 @@ public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boo if (id != null) { Set stepDefinitions = new HashSet<>(); for (IProject project : gherkinFile.getProject().getWorkspace().getRoot().getProjects()) { - StepDefinitionsRepository repository = StepDefinitionsStorage.INSTANCE - .getOrCreate(project, null); - stepDefinitions.addAll(repository.getAllStepDefinitions()); + try { + if (project.isOpen()) { + StepDefinitionsRepository repository = StepDefinitionsStorage.INSTANCE + .getOrCreate(project, null); + stepDefinitions.addAll(repository.getAllStepDefinitions()); + } + } catch (Exception e) { + e.printStackTrace(); + } } for (StepDefinition stepDefinition : stepDefinitions) { if (id.equals(stepDefinition.getId())) {