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

Pattern variants #18

Open
wants to merge 2 commits 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
Binary file removed lib/jbehave-core-3.5.4.jar
Binary file not shown.
Binary file added lib/jbehave-core-3.6.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
import com.intellij.psi.PsiLiteral;
import org.jbehave.core.annotations.Alias;
import org.jbehave.core.annotations.Aliases;
import org.jbehave.core.steps.PatternVariantBuilder;
import org.jbehave.core.steps.StepType;

import java.util.List;
import java.util.Set;

import static com.github.kumaraman21.intellijbehave.utility.StepTypeMappings.ANNOTATION_TO_STEP_TYPE_MAPPING;
Expand All @@ -37,27 +39,32 @@ public Set<StepDefinitionAnnotation> convertFrom(PsiAnnotation[] annotations) {

for (PsiAnnotation annotation : annotations) {
// Given, When, Then
if(ANNOTATION_TO_STEP_TYPE_MAPPING.keySet().contains(annotation.getQualifiedName())) {
if (ANNOTATION_TO_STEP_TYPE_MAPPING.keySet().contains(annotation.getQualifiedName())) {
stepType = ANNOTATION_TO_STEP_TYPE_MAPPING.get(annotation.getQualifiedName());
String annotationText = getTextFromValue(annotation.getParameterList().getAttributes()[0].getValue());
stepDefinitionAnnotations.add(new StepDefinitionAnnotation(stepType, annotationText, annotation));
}
else if(annotation.getQualifiedName().equals(Alias.class.getName())) {
stepDefinitionAnnotations.addAll(getPatternVariants(stepType, annotationText, annotation));
} else if (annotation.getQualifiedName().equals(Alias.class.getName())) {
String annotationText = getTextFromValue(annotation.getParameterList().getAttributes()[0].getValue());
stepDefinitionAnnotations.add(new StepDefinitionAnnotation(stepType, annotationText, annotation));
}
else if(annotation.getQualifiedName().equals(Aliases.class.getName())) {

stepDefinitionAnnotations.addAll(getPatternVariants(stepType, annotationText, annotation));
} else if (annotation.getQualifiedName().equals(Aliases.class.getName())) {
PsiElement[] values = annotation.getParameterList().getAttributes()[0].getValue().getChildren();
for (PsiElement value : values) {
if(value instanceof PsiLiteral) {
if (value instanceof PsiLiteral) {
String annotationText = getTextFromValue(value);
stepDefinitionAnnotations.add(new StepDefinitionAnnotation(stepType, annotationText, annotation));
stepDefinitionAnnotations.addAll(getPatternVariants(stepType, annotationText, annotation));
}
}
}
}
return stepDefinitionAnnotations;
}

private Set<StepDefinitionAnnotation> getPatternVariants(StepType stepType, String annotationText, PsiAnnotation annotation) {
Set<StepDefinitionAnnotation> stepDefinitionAnnotations = newHashSet();
PatternVariantBuilder b = new PatternVariantBuilder(annotationText);
for (String variant : b.allVariants()) {
stepDefinitionAnnotations.add(new StepDefinitionAnnotation(stepType, variant, annotation));
}
return stepDefinitionAnnotations;
}

Expand Down