From f092f1f55959129d8d2933db08774487b0d0fda2 Mon Sep 17 00:00:00 2001 From: AndreeaCh Date: Sun, 14 Jul 2013 13:02:30 +0300 Subject: [PATCH] Fixed issue #20- when starting a scenario with an "And" step, there is no previous step and the StoryParser is not able to set the step type. => set the first type to "GIVEN" --- .../intellijbehave/parser/StoryParser.java | 190 +++++++++--------- .../settings/JBehaveConfigurable.java | 2 +- 2 files changed, 96 insertions(+), 96 deletions(-) diff --git a/src/com/github/kumaraman21/intellijbehave/parser/StoryParser.java b/src/com/github/kumaraman21/intellijbehave/parser/StoryParser.java index 93c81cf..a54aa9a 100644 --- a/src/com/github/kumaraman21/intellijbehave/parser/StoryParser.java +++ b/src/com/github/kumaraman21/intellijbehave/parser/StoryParser.java @@ -25,114 +25,114 @@ import static com.github.kumaraman21.intellijbehave.utility.StepTypeMappings.STEP_TEXT_TO_STORY_ELEMENT_TYPE_MAPPING; public class StoryParser implements PsiParser { - @NotNull - @Override - public ASTNode parse(IElementType root, PsiBuilder builder) { - final PsiBuilder.Marker rootMarker = builder.mark(); - - parseStory(builder); - - rootMarker.done(root); - return builder.getTreeBuilt(); - } - - private void parseStory(PsiBuilder builder) { - final PsiBuilder.Marker storyMarker = builder.mark(); - parseStoryDescriptionLinesIfPresent(builder); - parseScenarios(builder); - storyMarker.done(StoryElementType.STORY); - } - - private void parseStoryDescriptionLinesIfPresent(PsiBuilder builder) { - if(builder.getTokenType() == StoryTokenType.STORY_DESCRIPTION) { - while(builder.getTokenType() == StoryTokenType.STORY_DESCRIPTION) { - parseStoryDescriptionLine(builder); - } - } - } - - private void parseStoryDescriptionLine(PsiBuilder builder) { - builder.advanceLexer(); - } - - private void parseScenarios(PsiBuilder builder) { - if(builder.getTokenType() == StoryTokenType.SCENARIO_TEXT) { - while(builder.getTokenType() == StoryTokenType.SCENARIO_TEXT) { - parseScenario(builder); - } - } - else { - builder.advanceLexer(); - builder.error("Scenario expected"); + @NotNull + @Override + public ASTNode parse(IElementType root, PsiBuilder builder) { + final PsiBuilder.Marker rootMarker = builder.mark(); + + parseStory(builder); + + rootMarker.done(root); + return builder.getTreeBuilt(); } - } - - private void parseScenario(PsiBuilder builder) { - final PsiBuilder.Marker stepMarker = builder.mark(); - builder.advanceLexer(); - parseSteps(builder); - parseStoryDescriptionLinesIfPresent(builder); - stepMarker.done(StoryElementType.SCENARIO); - } - - private void parseSteps(PsiBuilder builder) { - parseStoryDescriptionLinesIfPresent(builder); - if(builder.getTokenType() == StoryTokenType.STEP_TYPE) { - - StoryElementType previousStepElementType = null; - while(builder.getTokenType() == StoryTokenType.STEP_TYPE) { - previousStepElementType = parseStep(builder, previousStepElementType); + + private void parseStory(PsiBuilder builder) { + final PsiBuilder.Marker storyMarker = builder.mark(); parseStoryDescriptionLinesIfPresent(builder); - } + parseScenarios(builder); + storyMarker.done(StoryElementType.STORY); } - else { - builder.error("At least one step expected"); + + private void parseStoryDescriptionLinesIfPresent(PsiBuilder builder) { + if (builder.getTokenType() == StoryTokenType.STORY_DESCRIPTION) { + while (builder.getTokenType() == StoryTokenType.STORY_DESCRIPTION) { + parseStoryDescriptionLine(builder); + } + } } - } - private StoryElementType parseStep(PsiBuilder builder, StoryElementType previousStepElementType) { - final PsiBuilder.Marker stepMarker = builder.mark(); + private void parseStoryDescriptionLine(PsiBuilder builder) { + builder.advanceLexer(); + } - StoryElementType currentStepElementType; + private void parseScenarios(PsiBuilder builder) { + if (builder.getTokenType() == StoryTokenType.SCENARIO_TEXT) { + while (builder.getTokenType() == StoryTokenType.SCENARIO_TEXT) { + parseScenario(builder); + } + } else { + builder.advanceLexer(); + builder.error("Scenario expected"); + } + } - String stepTypeText = builder.getTokenText().trim().toUpperCase(); - if(stepTypeText.equalsIgnoreCase("And")) { - currentStepElementType = previousStepElementType; + private void parseScenario(PsiBuilder builder) { + final PsiBuilder.Marker stepMarker = builder.mark(); + builder.advanceLexer(); + parseSteps(builder); + parseStoryDescriptionLinesIfPresent(builder); + stepMarker.done(StoryElementType.SCENARIO); } - else { - currentStepElementType = STEP_TEXT_TO_STORY_ELEMENT_TYPE_MAPPING.get(stepTypeText); + + private void parseSteps(PsiBuilder builder) { + parseStoryDescriptionLinesIfPresent(builder); + if (builder.getTokenType() == StoryTokenType.STEP_TYPE) { + + StoryElementType previousStepElementType = null; + while (builder.getTokenType() == StoryTokenType.STEP_TYPE) { + previousStepElementType = parseStep(builder, previousStepElementType); + parseStoryDescriptionLinesIfPresent(builder); + } + } else { + builder.error("At least one step expected"); + } } - parseStepType(builder); - parseStepText(builder); - parseTableIfPresent(builder); - stepMarker.done(currentStepElementType); + private StoryElementType parseStep(PsiBuilder builder, StoryElementType previousStepElementType) { + final PsiBuilder.Marker stepMarker = builder.mark(); + + StoryElementType currentStepElementType; - return currentStepElementType; - } + String stepTypeText = builder.getTokenText().trim().toUpperCase(); + if (stepTypeText.equalsIgnoreCase("And")) { + if (previousStepElementType != null) { + currentStepElementType = previousStepElementType; + } else { //If there is no previous step, set the first step type to "GIVEN". + currentStepElementType = STEP_TEXT_TO_STORY_ELEMENT_TYPE_MAPPING.get("GIVEN"); + } + } else { + currentStepElementType = STEP_TEXT_TO_STORY_ELEMENT_TYPE_MAPPING.get(stepTypeText); + } - private void parseStepType(PsiBuilder builder) { - builder.advanceLexer(); - } + parseStepType(builder); + parseStepText(builder); + parseTableIfPresent(builder); + stepMarker.done(currentStepElementType); - private void parseStepText(PsiBuilder builder) { - if(builder.getTokenType() == StoryTokenType.STEP_TEXT) { - builder.advanceLexer(); + return currentStepElementType; } - else { - builder.error("Step text expected"); + + private void parseStepType(PsiBuilder builder) { + builder.advanceLexer(); + } + + private void parseStepText(PsiBuilder builder) { + if (builder.getTokenType() == StoryTokenType.STEP_TEXT) { + builder.advanceLexer(); + } else { + builder.error("Step text expected"); + } + } + + private void parseTableIfPresent(PsiBuilder builder) { + if (builder.getTokenType() == StoryTokenType.TABLE_ROW) { + while (builder.getTokenType() == StoryTokenType.TABLE_ROW) { + parseTableRow(builder); + } + } + } + + private void parseTableRow(PsiBuilder builder) { + builder.advanceLexer(); } - } - - private void parseTableIfPresent(PsiBuilder builder) { - if(builder.getTokenType() == StoryTokenType.TABLE_ROW) { - while(builder.getTokenType() == StoryTokenType.TABLE_ROW) { - parseTableRow(builder); - } - } - } - - private void parseTableRow(PsiBuilder builder) { - builder.advanceLexer(); - } } diff --git a/src/com/github/kumaraman21/intellijbehave/settings/JBehaveConfigurable.java b/src/com/github/kumaraman21/intellijbehave/settings/JBehaveConfigurable.java index 9bef0c3..fbd14c1 100644 --- a/src/com/github/kumaraman21/intellijbehave/settings/JBehaveConfigurable.java +++ b/src/com/github/kumaraman21/intellijbehave/settings/JBehaveConfigurable.java @@ -42,7 +42,7 @@ public String getDisplayName() { return "JBehave"; } - @Override + //@Override public Icon getIcon() { return null; }