Search in sources :

Example 1 with SnippetGenerator

use of cucumber.runtime.snippets.SnippetGenerator in project intellij-plugins by JetBrains.

the class Java8StepDefinitionCreator method buildStepDefinitionByStep.

private static PsiElement buildStepDefinitionByStep(@NotNull final GherkinStep step, Language language) {
    final Step cucumberStep = new Step(new ArrayList<>(), step.getKeyword().getText(), step.getStepName(), 0, null, null);
    final SnippetGenerator generator = new SnippetGenerator(new Java8Snippet());
    final String snippet = generator.getSnippet(cucumberStep, new FunctionNameGenerator(new CamelCaseConcatenator())).replace("PendingException", CucumberJavaUtil.getCucumberPendingExceptionFqn(step)).replaceAll("\\\\\\\\", "\\\\").replaceAll("\\\\d", "\\\\\\\\d");
    JVMElementFactory factory = JVMElementFactories.requireFactory(language, step.getProject());
    return factory.createExpressionFromText(snippet, step);
}
Also used : CamelCaseConcatenator(cucumber.runtime.snippets.CamelCaseConcatenator) SnippetGenerator(cucumber.runtime.snippets.SnippetGenerator) FunctionNameGenerator(cucumber.runtime.snippets.FunctionNameGenerator) Step(gherkin.formatter.model.Step) GherkinStep(org.jetbrains.plugins.cucumber.psi.GherkinStep)

Example 2 with SnippetGenerator

use of cucumber.runtime.snippets.SnippetGenerator in project intellij-plugins by JetBrains.

the class GrStepDefinitionCreator method buildStepDefinitionByStep.

private static GrMethodCall buildStepDefinitionByStep(@NotNull final GherkinStep step) {
    final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(step.getProject());
    final Step cucumberStep = new Step(Collections.emptyList(), step.getKeyword().getText(), step.getStepName(), 0, null, null);
    SnippetGenerator generator = new SnippetGenerator(new GroovySnippet());
    final String fqnPendingException;
    if (GrCucumberUtil.isCucumber_1_1_orAbove(step)) {
        fqnPendingException = "cucumber.api.PendingException";
    } else {
        fqnPendingException = "cucumber.runtime.PendingException";
    }
    String snippet = generator.getSnippet(cucumberStep, null).replace("PendingException", fqnPendingException);
    return (GrMethodCall) factory.createStatementFromText(snippet, step);
}
Also used : GroovyPsiElementFactory(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory) GrMethodCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall) SnippetGenerator(cucumber.runtime.snippets.SnippetGenerator) Step(gherkin.formatter.model.Step) GherkinStep(org.jetbrains.plugins.cucumber.psi.GherkinStep) GroovySnippet(cucumber.runtime.groovy.GroovySnippet)

Example 3 with SnippetGenerator

use of cucumber.runtime.snippets.SnippetGenerator in project intellij-plugins by JetBrains.

the class JavaStepDefinitionCreator method buildStepDefinitionByStep.

private static PsiMethod buildStepDefinitionByStep(@NotNull final GherkinStep step, Language language) {
    String annotationPackage = new AnnotationPackageProvider().getAnnotationPackageFor(step);
    String methodAnnotation = String.format("@%s.", annotationPackage);
    final Step cucumberStep = new Step(new ArrayList<>(), step.getKeyword().getText(), step.getStepName(), 0, null, null);
    final SnippetGenerator generator = new SnippetGenerator(new JavaSnippet());
    final String snippet = generator.getSnippet(cucumberStep, new FunctionNameGenerator(new CamelCaseConcatenator())).replace("PendingException", CucumberJavaUtil.getCucumberPendingExceptionFqn(step)).replaceFirst("@", methodAnnotation).replaceAll("\\\\\\\\", "\\\\").replaceAll("\\\\d", "\\\\\\\\d");
    JVMElementFactory factory = JVMElementFactories.requireFactory(language, step.getProject());
    return factory.createMethodFromText(snippet, step);
}
Also used : CamelCaseConcatenator(cucumber.runtime.snippets.CamelCaseConcatenator) SnippetGenerator(cucumber.runtime.snippets.SnippetGenerator) FunctionNameGenerator(cucumber.runtime.snippets.FunctionNameGenerator) Step(gherkin.formatter.model.Step) GherkinStep(org.jetbrains.plugins.cucumber.psi.GherkinStep)

Aggregations

SnippetGenerator (cucumber.runtime.snippets.SnippetGenerator)3 Step (gherkin.formatter.model.Step)3 GherkinStep (org.jetbrains.plugins.cucumber.psi.GherkinStep)3 CamelCaseConcatenator (cucumber.runtime.snippets.CamelCaseConcatenator)2 FunctionNameGenerator (cucumber.runtime.snippets.FunctionNameGenerator)2 GroovySnippet (cucumber.runtime.groovy.GroovySnippet)1 GroovyPsiElementFactory (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory)1 GrMethodCall (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall)1