Package org.jetbrains.plugins.cucumber.steps

Source Code of org.jetbrains.plugins.cucumber.steps.AbstractCucumberExtension

package org.jetbrains.plugins.cucumber.steps;

import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleUtilCore;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.cucumber.CucumberJvmExtensionPoint;
import org.jetbrains.plugins.cucumber.psi.GherkinStep;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;

/**
* User: Andrey.Vokin
* Date: 6/28/13
*/
public abstract class AbstractCucumberExtension implements CucumberJvmExtensionPoint {
  @Override
  public List<PsiElement> resolveStep(@NotNull final PsiElement element) {
    final Module module = ModuleUtilCore.findModuleForPsiElement(element);
    if (module == null) {
      return Collections.emptyList();
    }

    final Set<String> stepVariants = getAllPossibleStepVariants(element);

    final List<AbstractStepDefinition> stepDefinitions = loadStepsFor(element.getContainingFile(), module);
    final List<PsiElement> result = new ArrayList<PsiElement>();

    if (! (element instanceof GherkinStep)) {
      return result; // Not a step, so there is nothing to check
    }

    final GherkinStep step = (GherkinStep)element;

    for (final AbstractStepDefinition stepDefinition : stepDefinitions) {
      for (final String s : stepVariants) {
        if (stepDefinition.matches(s) && stepDefinition.supportsStep(step)) {
          result.add(stepDefinition.getElement());
        }
      }
    }

    return result;
  }

  protected Set<String> getAllPossibleStepVariants(@NotNull final PsiElement element) {
    if (element instanceof GherkinStep) {
      return ((GherkinStep)element).getSubstitutedNameList();
    }
    return Collections.emptySet();
  }

  @Override
  public void flush(@NotNull final Project project) {
  }

  @Override
  public void reset(@NotNull final Project project) {
  }

  @Override
  public Object getDataObject(@NotNull Project project) {
    return null;
  }
}
TOP

Related Classes of org.jetbrains.plugins.cucumber.steps.AbstractCucumberExtension

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.