Search in sources :

Example 71 with Location

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;
}
Also used : Module(com.intellij.openapi.module.Module) Location(com.intellij.execution.Location)

Example 72 with Location

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) PsiLocation(com.intellij.execution.PsiLocation) PsiLocation(com.intellij.execution.PsiLocation) Location(com.intellij.execution.Location)

Example 73 with Location

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);
}
Also used : GoFunctionIndex(com.goide.stubs.index.GoFunctionIndex) GoTypeSpec(com.goide.psi.GoTypeSpec) GoTypesIndex(com.goide.stubs.index.GoTypesIndex) StringUtil(com.intellij.openapi.util.text.StringUtil) GoMethodDeclaration(com.goide.psi.GoMethodDeclaration) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) IdFilter(com.intellij.util.indexing.IdFilter) ContainerUtil(com.intellij.util.containers.ContainerUtil) PsiLocation(com.intellij.execution.PsiLocation) SMTestLocator(com.intellij.execution.testframework.sm.runner.SMTestLocator) GoIdFilter(com.goide.stubs.index.GoIdFilter) List(java.util.List) Project(com.intellij.openapi.project.Project) Location(com.intellij.execution.Location) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) IdFilter(com.intellij.util.indexing.IdFilter) GoIdFilter(com.goide.stubs.index.GoIdFilter) GoMethodDeclaration(com.goide.psi.GoMethodDeclaration) GoTypeSpec(com.goide.psi.GoTypeSpec) PsiLocation(com.intellij.execution.PsiLocation) Location(com.intellij.execution.Location) NotNull(org.jetbrains.annotations.NotNull)

Example 74 with Location

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);
}
Also used : Location(com.intellij.execution.Location)

Example 75 with Location

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));
}
Also used : RunConfiguration(com.intellij.execution.configurations.RunConfiguration) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) TargetExpression(com.google.idea.blaze.base.model.primitives.TargetExpression) BlazeTestEventsHandler(com.google.idea.blaze.base.run.smrunner.BlazeTestEventsHandler) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Location(com.intellij.execution.Location)

Aggregations

Location (com.intellij.execution.Location)79 PsiClass (com.intellij.psi.PsiClass)27 PsiElement (com.intellij.psi.PsiElement)26 VirtualFile (com.intellij.openapi.vfs.VirtualFile)20 PsiMethod (com.intellij.psi.PsiMethod)19 PsiLocation (com.intellij.execution.PsiLocation)18 Project (com.intellij.openapi.project.Project)18 PsiMemberParameterizedLocation (com.intellij.execution.junit2.PsiMemberParameterizedLocation)17 MethodLocation (com.intellij.execution.junit2.info.MethodLocation)16 Module (com.intellij.openapi.module.Module)14 Nullable (org.jetbrains.annotations.Nullable)9 PsiFile (com.intellij.psi.PsiFile)8 ArrayList (java.util.ArrayList)8 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)7 SMTestProxy (com.intellij.execution.testframework.sm.runner.SMTestProxy)6 NotNull (org.jetbrains.annotations.NotNull)6 Nullable (javax.annotation.Nullable)5 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)4 PatternConfigurationProducer (com.intellij.execution.junit.PatternConfigurationProducer)4 Kind (com.google.idea.blaze.base.model.primitives.Kind)3