Search in sources :

Example 31 with Location

use of com.intellij.execution.Location in project intellij-plugins by JetBrains.

the class BndRunConfigurationProducer method setupConfigurationFromContext.

@Override
protected boolean setupConfigurationFromContext(BndRunConfigurationBase configuration, ConfigurationContext context, Ref<PsiElement> source) {
    Location location = context.getLocation();
    if (location != null) {
        VirtualFile file = location.getVirtualFile();
        if (file != null && !file.isDirectory()) {
            String extension = file.getExtension();
            if (BndFileType.BND_RUN_EXT.equals(extension) || BndFileType.BND_EXT.equals(extension)) {
                Boolean hasTestCases = BndLaunchUtil.hasTestCases(file.getPath());
                if (hasTestCases == Boolean.FALSE && configuration instanceof BndRunConfigurationBase.Launch || hasTestCases == Boolean.TRUE && configuration instanceof BndRunConfigurationBase.Test) {
                    configuration.setName(context.getModule().getName());
                    configuration.bndRunFile = file.getPath();
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Location(com.intellij.execution.Location)

Example 32 with Location

use of com.intellij.execution.Location in project Intellij-Plugin by getgauge.

the class GaugeExecutionProducer method isConfigurationFromContext.

@Override
public boolean isConfigurationFromContext(RunConfiguration configuration, ConfigurationContext context) {
    if (!(configuration.getType() instanceof GaugeRunTaskConfigurationType))
        return false;
    Location location = context.getLocation();
    PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(context.getDataContext());
    if (location == null || location.getVirtualFile() == null || element == null)
        return false;
    if (!isInSpecScope(context.getPsiLocation()))
        return false;
    String specsToExecute = ((GaugeRunConfiguration) configuration).getSpecsToExecute();
    return specsToExecute != null && (specsToExecute.equals(location.getVirtualFile().getPath()));
}
Also used : PsiElement(com.intellij.psi.PsiElement) Location(com.intellij.execution.Location)

Example 33 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 34 with Location

use of com.intellij.execution.Location in project android by JetBrains.

the class AndroidConfigurationProducer method setupConfigurationFromContext.

@Override
protected boolean setupConfigurationFromContext(AndroidRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    final Location location = context.getLocation();
    if (location == null) {
        return false;
    }
    final PsiClass activity = getActivityClass(location, context);
    if (activity == null) {
        return false;
    }
    final String activityName = activity.getQualifiedName();
    if (activityName == null) {
        return false;
    }
    sourceElement.set(activity);
    configuration.setLaunchActivity(activityName);
    configuration.setName(JavaExecutionUtil.getPresentableClassName(activityName));
    setupConfigurationModule(context, configuration);
    final TargetSelectionMode targetSelectionMode = AndroidUtils.getDefaultTargetSelectionMode(context.getModule(), AndroidRunConfigurationType.getInstance(), AndroidTestRunConfigurationType.getInstance());
    if (targetSelectionMode != null) {
        configuration.getDeployTargetContext().setTargetSelectionMode(targetSelectionMode);
    }
    return true;
}
Also used : PsiClass(com.intellij.psi.PsiClass) Location(com.intellij.execution.Location)

Example 35 with Location

use of com.intellij.execution.Location in project android by JetBrains.

the class AndroidJUnitConfigurations method isFromContext.

// Copy of JUnitConfigurationProducer#isConfigurationFromContext using AndroidJUnitConfigurationType instead of JUnitConfigurationType
public static boolean isFromContext(@NotNull JUnitConfiguration unitConfiguration, @NotNull ConfigurationContext context, @NotNull ConfigurationFactory configurationFactory) {
    if (RunConfigurationProducer.getInstance(PatternConfigurationProducer.class).isMultipleElementsSelected(context)) {
        return false;
    }
    RunConfiguration predefinedConfiguration = context.getOriginalConfiguration(AndroidJUnitConfigurationType.getInstance());
    Location contextLocation = context.getLocation();
    String paramSetName = contextLocation instanceof PsiMemberParameterizedLocation ? ((PsiMemberParameterizedLocation) contextLocation).getParamSetName() : null;
    assert contextLocation != null;
    Location location = JavaExecutionUtil.stepIntoSingleClass(contextLocation);
    if (location == null) {
        return false;
    }
    PsiElement element = location.getPsiElement();
    PsiClass testClass = getTestClass(element);
    PsiMethod testMethod = getTestMethod(element, false);
    PsiPackage testPackage;
    if (element instanceof PsiPackage) {
        testPackage = (PsiPackage) element;
    } else {
        if (element instanceof PsiDirectory) {
            testPackage = JavaDirectoryService.getInstance().getPackage(((PsiDirectory) element));
        } else {
            testPackage = null;
        }
    }
    PsiDirectory testDir = element instanceof PsiDirectory ? (PsiDirectory) element : null;
    RunnerAndConfigurationSettings template = RunManager.getInstance(location.getProject()).getConfigurationTemplate(configurationFactory);
    Module predefinedModule = ((JUnitConfiguration) template.getConfiguration()).getConfigurationModule().getModule();
    String vmParameters = predefinedConfiguration instanceof JUnitConfiguration ? ((JUnitConfiguration) predefinedConfiguration).getVMParameters() : null;
    if (vmParameters != null && !Comparing.strEqual(vmParameters, unitConfiguration.getVMParameters())) {
        return false;
    }
    if (paramSetName != null && !Comparing.strEqual(paramSetName, unitConfiguration.getProgramParameters())) {
        return false;
    }
    TestObject testobject = unitConfiguration.getTestObject();
    if (testobject != null) {
        if (testobject.isConfiguredByElement(unitConfiguration, testClass, testMethod, testPackage, testDir)) {
            Module configurationModule = unitConfiguration.getConfigurationModule().getModule();
            if (Comparing.equal(location.getModule(), configurationModule)) {
                return true;
            }
            if (Comparing.equal(predefinedModule, configurationModule)) {
                return true;
            }
        }
    }
    return false;
}
Also used : PatternConfigurationProducer(com.intellij.execution.junit.PatternConfigurationProducer) JUnitConfiguration(com.intellij.execution.junit.JUnitConfiguration) TestObject(com.intellij.execution.junit.TestObject) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) Module(com.intellij.openapi.module.Module) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation) Location(com.intellij.execution.Location)

Aggregations

Location (com.intellij.execution.Location)64 PsiElement (com.intellij.psi.PsiElement)21 PsiClass (com.intellij.psi.PsiClass)19 VirtualFile (com.intellij.openapi.vfs.VirtualFile)18 PsiMemberParameterizedLocation (com.intellij.execution.junit2.PsiMemberParameterizedLocation)17 PsiLocation (com.intellij.execution.PsiLocation)16 MethodLocation (com.intellij.execution.junit2.info.MethodLocation)16 Project (com.intellij.openapi.project.Project)15 Module (com.intellij.openapi.module.Module)13 PsiMethod (com.intellij.psi.PsiMethod)11 PsiFile (com.intellij.psi.PsiFile)8 Nullable (org.jetbrains.annotations.Nullable)8 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)7 SMTestProxy (com.intellij.execution.testframework.sm.runner.SMTestProxy)6 ArrayList (java.util.ArrayList)6 NotNull (org.jetbrains.annotations.NotNull)6 PatternConfigurationProducer (com.intellij.execution.junit.PatternConfigurationProducer)5 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)3 AbstractTestProxy (com.intellij.execution.testframework.AbstractTestProxy)3 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)3