Search in sources :

Example 46 with Location

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

the class GradleRunnerUtil method getData.

public static Object getData(@NotNull Project project, @NonNls String dataId, @NotNull ExecutionInfo executionInfo) {
    if (CommonDataKeys.NAVIGATABLE.is(dataId)) {
        final Location location = getLocation(project, executionInfo);
        final OpenFileDescriptor openFileDescriptor = location == null ? null : location.getOpenFileDescriptor();
        if (openFileDescriptor != null && openFileDescriptor.getFile().isValid()) {
            return openFileDescriptor;
        }
    }
    if (CommonDataKeys.PSI_ELEMENT.is(dataId)) {
        final Location location = getLocation(project, executionInfo);
        if (location != null) {
            final PsiElement element = location.getPsiElement();
            return element.isValid() ? element : null;
        } else {
            return null;
        }
    }
    if (Location.DATA_KEY.is(dataId))
        return getLocation(project, executionInfo);
    return null;
}
Also used : OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) PsiElement(com.intellij.psi.PsiElement) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation) ExternalSystemTaskLocation(com.intellij.openapi.externalSystem.service.execution.ExternalSystemTaskLocation) MethodLocation(com.intellij.execution.junit2.info.MethodLocation) Location(com.intellij.execution.Location)

Example 47 with Location

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

the class TestClassGradleConfigurationProducer method doIsConfigurationFromContext.

@Override
protected boolean doIsConfigurationFromContext(ExternalSystemRunConfiguration configuration, ConfigurationContext context) {
    final Location contextLocation = context.getLocation();
    assert contextLocation != null;
    if (RunConfigurationProducer.getInstance(PatternConfigurationProducer.class).isMultipleElementsSelected(context)) {
        return false;
    }
    if (getPsiMethodForLocation(contextLocation) != null)
        return false;
    PsiClass testClass = getPsiClassForLocation(contextLocation);
    if (testClass == null || testClass.getQualifiedName() == null)
        return false;
    if (context.getModule() == null)
        return false;
    final String projectPath = resolveProjectPath(context.getModule());
    if (projectPath == null)
        return false;
    if (!StringUtil.equals(projectPath, configuration.getSettings().getExternalProjectPath())) {
        return false;
    }
    if (!configuration.getSettings().getTaskNames().containsAll(getTasksToRun(context.getModule())))
        return false;
    final String scriptParameters = configuration.getSettings().getScriptParameters() + ' ';
    int i = scriptParameters.indexOf("--tests ");
    if (i == -1)
        return false;
    String str = scriptParameters.substring(i + "--tests ".length()).trim() + ' ';
    return str.startsWith(testClass.getQualifiedName() + ' ') && !str.contains("--tests");
}
Also used : PatternConfigurationProducer(com.intellij.execution.junit.PatternConfigurationProducer) PsiClass(com.intellij.psi.PsiClass) GradleRunnerUtil.getMethodLocation(org.jetbrains.plugins.gradle.execution.GradleRunnerUtil.getMethodLocation) Location(com.intellij.execution.Location)

Example 48 with Location

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

the class TestClassGradleConfigurationProducer method doSetupConfigurationFromContext.

@Override
protected boolean doSetupConfigurationFromContext(ExternalSystemRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    final Location contextLocation = context.getLocation();
    assert contextLocation != null;
    if (RunConfigurationProducer.getInstance(PatternConfigurationProducer.class).isMultipleElementsSelected(context)) {
        return false;
    }
    PsiClass testClass = getPsiClassForLocation(contextLocation);
    if (testClass == null) {
        return false;
    }
    sourceElement.set(testClass);
    final Module module = context.getModule();
    if (module == null)
        return false;
    if (!ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, module))
        return false;
    final String projectPath = resolveProjectPath(module);
    if (projectPath == null)
        return false;
    List<String> tasksToRun = getTasksToRun(module);
    if (tasksToRun.isEmpty())
        return false;
    configuration.getSettings().setExternalProjectPath(projectPath);
    configuration.getSettings().setTaskNames(tasksToRun);
    configuration.getSettings().setScriptParameters(String.format("--tests %s", testClass.getQualifiedName()));
    configuration.setName(testClass.getName());
    JavaRunConfigurationExtensionManager.getInstance().extendCreatedConfiguration(configuration, contextLocation);
    return true;
}
Also used : PatternConfigurationProducer(com.intellij.execution.junit.PatternConfigurationProducer) PsiClass(com.intellij.psi.PsiClass) Module(com.intellij.openapi.module.Module) GradleRunnerUtil.getMethodLocation(org.jetbrains.plugins.gradle.execution.GradleRunnerUtil.getMethodLocation) Location(com.intellij.execution.Location)

Example 49 with Location

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

the class TestMethodGradleConfigurationProducer method doIsConfigurationFromContext.

@Override
protected boolean doIsConfigurationFromContext(ExternalSystemRunConfiguration configuration, ConfigurationContext context) {
    if (RunConfigurationProducer.getInstance(PatternConfigurationProducer.class).isMultipleElementsSelected(context)) {
        return false;
    }
    final Location contextLocation = context.getLocation();
    assert contextLocation != null;
    PsiMethod psiMethod = getPsiMethodForLocation(contextLocation);
    if (psiMethod == null)
        return false;
    final PsiClass containingClass = psiMethod.getContainingClass();
    if (containingClass == null)
        return false;
    final Module module = context.getModule();
    if (module == null)
        return false;
    final String projectPath = resolveProjectPath(module);
    if (projectPath == null)
        return false;
    if (!StringUtil.equals(projectPath, configuration.getSettings().getExternalProjectPath())) {
        return false;
    }
    if (!configuration.getSettings().getTaskNames().containsAll(getTasksToRun(module)))
        return false;
    final String scriptParameters = configuration.getSettings().getScriptParameters() + ' ';
    final String testFilter = createTestFilter(containingClass, psiMethod);
    return scriptParameters.contains(testFilter);
}
Also used : PatternConfigurationProducer(com.intellij.execution.junit.PatternConfigurationProducer) PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) Module(com.intellij.openapi.module.Module) GradleRunnerUtil.getMethodLocation(org.jetbrains.plugins.gradle.execution.GradleRunnerUtil.getMethodLocation) Location(com.intellij.execution.Location)

Example 50 with Location

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

the class AbstractTestNGPackageConfigurationProducer method setupConfigurationFromContext.

@Override
protected boolean setupConfigurationFromContext(TestNGConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    final PsiElement element = context.getPsiLocation();
    PsiPackage aPackage = JavaRuntimeConfigurationProducerBase.checkPackage(element);
    if (aPackage == null) {
        return false;
    }
    final Location location = context.getLocation();
    if (location == null) {
        return false;
    }
    if (!LocationUtil.isJarAttached(location, aPackage, TestNGUtil.TEST_ANNOTATION_FQN)) {
        return false;
    }
    final TestData data = configuration.data;
    data.PACKAGE_NAME = aPackage.getQualifiedName();
    data.TEST_OBJECT = TestType.PACKAGE.getType();
    data.setScope(setupPackageConfiguration(context, configuration, data.getScope()));
    configuration.setGeneratedName();
    sourceElement.set(aPackage);
    return true;
}
Also used : TestData(com.theoryinpractice.testng.model.TestData) PsiPackage(com.intellij.psi.PsiPackage) PsiElement(com.intellij.psi.PsiElement) 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