use of com.intellij.execution.Location in project intellij-community by JetBrains.
the class PythonTestLegacyConfigurationProducer method setupConfigurationFromContext.
@Override
protected boolean setupConfigurationFromContext(AbstractPythonLegacyTestRunConfiguration<T> configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
if (context == null)
return false;
final Location location = context.getLocation();
if (location == null || !isAvailable(location))
return false;
PsiElement element = location.getPsiElement();
if (element instanceof PsiWhiteSpace) {
element = PyUtil.findNonWhitespaceAtOffset(element.getContainingFile(), element.getTextOffset());
}
if (PythonUnitTestRunnableScriptFilter.isIfNameMain(location))
return false;
final Module module = location.getModule();
if (!isPythonModule(module))
return false;
if (element instanceof PsiDirectory) {
return setupConfigurationFromFolder((PsiDirectory) element, configuration);
}
final PyFunction pyFunction = PsiTreeUtil.getParentOfType(element, PyFunction.class, false);
if (pyFunction != null && isTestFunction(pyFunction, configuration)) {
return setupConfigurationFromFunction(pyFunction, configuration);
}
final PyClass pyClass = PsiTreeUtil.getParentOfType(element, PyClass.class, false);
if (pyClass != null && isTestClass(pyClass, configuration, TypeEvalContext.userInitiated(pyClass.getProject(), element.getContainingFile()))) {
return setupConfigurationFromClass(pyClass, configuration);
}
if (element == null)
return false;
final PsiFile file = element.getContainingFile();
if (file instanceof PyFile && isTestFile((PyFile) file)) {
return setupConfigurationFromFile((PyFile) file, configuration);
}
return false;
}
use of com.intellij.execution.Location in project intellij-community by JetBrains.
the class PythonUnitTestUtil method findLocations.
public static List<Location> findLocations(@NotNull final Project project, @NotNull String fileName, @Nullable String className, @Nullable String methodName) {
if (fileName.contains("%")) {
fileName = fileName.substring(0, fileName.lastIndexOf("%"));
}
final List<Location> locations = new ArrayList<>();
if (methodName == null && className == null) {
final VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByPath(fileName);
if (virtualFile == null)
return locations;
final PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
if (psiFile != null) {
locations.add(new PsiLocation<>(project, psiFile));
}
}
if (className != null) {
for (PyClass cls : PyClassNameIndex.find(className, project, false)) {
ProgressManager.checkCanceled();
final PsiFile containingFile = cls.getContainingFile();
final VirtualFile virtualFile = containingFile.getVirtualFile();
final String clsFileName = virtualFile == null ? containingFile.getName() : virtualFile.getPath();
final String clsFileNameWithoutExt = FileUtil.getNameWithoutExtension(clsFileName);
if (!clsFileNameWithoutExt.endsWith(fileName) && !fileName.equals(clsFileName)) {
continue;
}
if (methodName == null) {
locations.add(new PsiLocation<>(project, cls));
} else {
final PyFunction method = cls.findMethodByName(methodName, true, null);
if (method == null) {
continue;
}
locations.add(new PyPsiLocationWithFixedClass(project, method, cls));
}
}
} else if (methodName != null) {
for (PyFunction function : PyFunctionNameIndex.find(methodName, project)) {
ProgressManager.checkCanceled();
if (function.getContainingClass() == null) {
final PsiFile containingFile = function.getContainingFile();
final VirtualFile virtualFile = containingFile.getVirtualFile();
final String clsFileName = virtualFile == null ? containingFile.getName() : virtualFile.getPath();
final String clsFileNameWithoutExt = FileUtil.getNameWithoutExtension(clsFileName);
if (!clsFileNameWithoutExt.endsWith(fileName)) {
continue;
}
locations.add(new PsiLocation<>(project, function));
}
}
}
return locations;
}
use of com.intellij.execution.Location in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoTestLocator method getLocation.
@NotNull
@Override
public List<Location> getLocation(@NotNull String protocolId, @NotNull String path, @NotNull Project project, @NotNull GlobalSearchScope scope) {
if (PROTOCOL.equals(protocolId)) {
IdFilter idFilter = GoIdFilter.getTestsFilter(project);
List<String> locationDataItems = StringUtil.split(path, ".");
// Location is a function name, e.g. `TestCheckItOut`
if (locationDataItems.size() == 1) {
return ContainerUtil.mapNotNull(GoFunctionIndex.find(path, project, scope, idFilter), function -> PsiLocation.fromPsiElement(project, function));
}
// Location is a method name, e.g. `FooSuite.TestCheckItOut`
if (locationDataItems.size() == 2) {
List<Location> locations = ContainerUtil.newArrayList();
for (GoTypeSpec typeSpec : GoTypesIndex.find(locationDataItems.get(0), project, scope, idFilter)) {
for (GoMethodDeclaration method : typeSpec.getMethods()) {
if (locationDataItems.get(1).equals(method.getName())) {
ContainerUtil.addIfNotNull(locations, PsiLocation.fromPsiElement(method));
}
}
}
return locations;
}
} else if (SUITE_PROTOCOL.equals(protocolId)) {
IdFilter idFilter = GoIdFilter.getTestsFilter(project);
return ContainerUtil.mapNotNull(GoTypesIndex.find(path, project, scope, idFilter), spec -> PsiLocation.fromPsiElement(project, spec));
} else {
return Collections.emptyList();
}
throw new RuntimeException("Unsupported location: " + path);
}
use of com.intellij.execution.Location in project Intellij-Plugin by getgauge.
the class ScenarioExecutionProducer method isConfigurationFromContext.
@Override
public boolean isConfigurationFromContext(RunConfiguration configuration, ConfigurationContext context) {
if (!(configuration.getType() instanceof GaugeRunTaskConfigurationType))
return false;
Location location = context.getLocation();
if (location == null || location.getVirtualFile() == null || context.getPsiLocation() == null)
return false;
String specsToExecute = ((GaugeRunConfiguration) configuration).getSpecsToExecute();
int identifier = getScenarioIdentifier(context, context.getPsiLocation().getContainingFile());
return specsToExecute != null && specsToExecute.equals(location.getVirtualFile().getPath() + Constants.SPEC_SCENARIO_DELIMITER + identifier);
}
use of com.intellij.execution.Location in project intellij by bazelbuild.
the class BlazeFilterExistingRunConfigurationProducer method getTestFilter.
private static Optional<String> getTestFilter(ConfigurationContext context) {
RunConfiguration base = context.getOriginalConfiguration(null);
if (!(base instanceof BlazeCommandRunConfiguration)) {
return Optional.empty();
}
TargetExpression target = ((BlazeCommandRunConfiguration) base).getTarget();
if (target == null) {
return Optional.empty();
}
List<Location<?>> selectedElements = SmRunnerUtils.getSelectedSmRunnerTreeElements(context);
if (selectedElements.isEmpty()) {
return null;
}
Optional<BlazeTestEventsHandler> testEventsHandler = BlazeTestEventsHandler.getHandlerForTarget(context.getProject(), target);
return testEventsHandler.map(handler -> handler.getTestFilter(context.getProject(), selectedElements));
}
Aggregations