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

NullPointerException (and plugin crash) occurs when a scenario is started with an "And" step. #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
190 changes: 95 additions & 95 deletions src/com/github/kumaraman21/intellijbehave/parser/StoryParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public String getDisplayName() {
return "JBehave";
}

@Override
//@Override
public Icon getIcon() {
return null;
}
Expand Down