Search in sources :

Example 41 with Location

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

the class CucumberJavaRunConfigurationProducer method setupConfigurationFromContext.

@Override
protected boolean setupConfigurationFromContext(CucumberJavaRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    final VirtualFile virtualFile = getFileToRun(context);
    if (virtualFile == null) {
        return false;
    }
    final Project project = configuration.getProject();
    final PsiElement element = context.getPsiLocation();
    if (element == null) {
        return false;
    }
    final Module module = ModuleUtilCore.findModuleForFile(virtualFile, project);
    if (module == null)
        return false;
    String mainClassName = null;
    String formatterOptions = null;
    final Location location = context.getLocation();
    if (location != null) {
        if (LocationUtil.isJarAttached(location, PsiDirectory.EMPTY_ARRAY, CUCUMBER_1_0_MAIN_CLASS)) {
            mainClassName = CUCUMBER_1_0_MAIN_CLASS;
        } else if (LocationUtil.isJarAttached(location, PsiDirectory.EMPTY_ARRAY, CUCUMBER_1_1_MAIN_CLASS)) {
            mainClassName = CUCUMBER_1_1_MAIN_CLASS;
        }
        if (LocationUtil.isJarAttached(location, PsiDirectory.EMPTY_ARRAY, CUCUMBER_1_2_PLUGIN_CLASS)) {
            formatterOptions = FORMATTER_OPTIONS_1_2;
        } else {
            formatterOptions = FORMATTER_OPTIONS;
        }
    }
    if (mainClassName == null) {
        return false;
    }
    final VirtualFile file = getFileToRun(context);
    if (file == null) {
        return false;
    }
    if (StringUtil.isEmpty(configuration.getGlue())) {
        final NullableComputable<String> glue = getStepsGlue(element);
        configuration.setGlue(glue);
    }
    configuration.setNameFilter(getNameFilter(context));
    configuration.setFilePath(file.getPath());
    configuration.setProgramParameters(formatterOptions);
    if (StringUtil.isEmpty(configuration.MAIN_CLASS_NAME)) {
        configuration.MAIN_CLASS_NAME = mainClassName;
    }
    if (configuration.getNameFilter() != null && configuration.getNameFilter().length() > 0) {
        final String newProgramParameters = configuration.getProgramParameters() + " --name \"" + configuration.getNameFilter() + "\"";
        configuration.setProgramParameters(newProgramParameters);
    }
    configuration.myGeneratedName = getConfigurationName(context);
    configuration.setGeneratedName();
    setupConfigurationModule(context, configuration);
    JavaRunConfigurationExtensionManager.getInstance().extendCreatedConfiguration(configuration, location);
    return true;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) Module(com.intellij.openapi.module.Module) Location(com.intellij.execution.Location)

Example 42 with Location

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

the class TestsUIUtil method getData.

@Nullable
public static Object getData(final AbstractTestProxy testProxy, final String dataId, final TestFrameworkRunningModel model) {
    final TestConsoleProperties properties = model.getProperties();
    final Project project = properties.getProject();
    if (testProxy == null)
        return null;
    if (AbstractTestProxy.DATA_KEY.is(dataId))
        return testProxy;
    if (CommonDataKeys.NAVIGATABLE.is(dataId))
        return getOpenFileDescriptor(testProxy, model);
    if (CommonDataKeys.PSI_ELEMENT.is(dataId)) {
        final Location location = testProxy.getLocation(project, properties.getScope());
        if (location != null) {
            final PsiElement element = location.getPsiElement();
            return element.isValid() ? element : null;
        } else {
            return null;
        }
    }
    if (Location.DATA_KEY.is(dataId))
        return testProxy.getLocation(project, properties.getScope());
    if (RunConfiguration.DATA_KEY.is(dataId)) {
        final RunProfile configuration = properties.getConfiguration();
        if (configuration instanceof RunConfiguration) {
            return configuration;
        }
    }
    return null;
}
Also used : Project(com.intellij.openapi.project.Project) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) RunProfile(com.intellij.execution.configurations.RunProfile) PsiElement(com.intellij.psi.PsiElement) Location(com.intellij.execution.Location) Nullable(org.jetbrains.annotations.Nullable)

Example 43 with Location

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

the class AbstractExcludeFromRunAction method update.

@Override
public void update(AnActionEvent e) {
    final Presentation presentation = e.getPresentation();
    presentation.setVisible(false);
    final DataContext dataContext = e.getDataContext();
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    if (project != null) {
        final RunConfiguration configuration = RunConfiguration.DATA_KEY.getData(dataContext);
        if (isPatternBasedConfiguration(configuration)) {
            final AbstractTestProxy testProxy = AbstractTestProxy.DATA_KEY.getData(dataContext);
            if (testProxy != null) {
                final Location location = testProxy.getLocation(project, ((T) configuration).getConfigurationModule().getSearchScope());
                if (location != null) {
                    final PsiElement psiElement = location.getPsiElement();
                    if (psiElement instanceof PsiClass && getPattern((T) configuration).contains(((PsiClass) psiElement).getQualifiedName())) {
                        presentation.setVisible(true);
                    }
                }
            }
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) PsiClass(com.intellij.psi.PsiClass) AbstractTestProxy(com.intellij.execution.testframework.AbstractTestProxy) PsiElement(com.intellij.psi.PsiElement) Location(com.intellij.execution.Location)

Example 44 with Location

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

the class TestLocationDataRule method getLocation.

@Nullable
private static Location getLocation(Project project, String fileName, String nameWithoutExtension, PsiClass aClass) {
    final PsiAnnotation annotation = AnnotationUtil.findAnnotation(aClass, TestDataPath.class.getName());
    if (annotation != null) {
        final Location parameterizedLocation = PsiMemberParameterizedLocation.getParameterizedLocation(aClass, "[" + fileName + "]", Parameterized.class.getName());
        if (parameterizedLocation != null) {
            return parameterizedLocation;
        }
        if (StringUtil.isJavaIdentifier(nameWithoutExtension)) {
            final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project);
            PsiMethod method = aClass.findMethodBySignature(elementFactory.createMethod("test" + nameWithoutExtension, PsiType.VOID), true);
            if (method != null) {
                return MethodLocation.elementInClass(method, aClass);
            }
            method = aClass.findMethodBySignature(elementFactory.createMethod("test" + StringUtil.capitalize(nameWithoutExtension), PsiType.VOID), true);
            if (method != null) {
                return MethodLocation.elementInClass(method, aClass);
            }
        }
        return new PsiLocation<PsiElement>(project, aClass);
    }
    return null;
}
Also used : TestDataPath(com.intellij.testFramework.TestDataPath) Parameterized(com.intellij.testFramework.Parameterized) PsiLocation(com.intellij.execution.PsiLocation) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation) PsiLocation(com.intellij.execution.PsiLocation) MethodLocation(com.intellij.execution.junit2.info.MethodLocation) Location(com.intellij.execution.Location) Nullable(org.jetbrains.annotations.Nullable)

Example 45 with Location

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

the class PatternGradleConfigurationProducer method doSetupConfigurationFromContext.

@Override
protected boolean doSetupConfigurationFromContext(ExternalSystemRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    final Location contextLocation = context.getLocation();
    assert contextLocation != null;
    final LinkedHashSet<String> tests = new LinkedHashSet<>();
    final PsiElement element = myBaseConfigurationProducer.checkPatterns(context, tests);
    if (element == null) {
        return false;
    }
    sourceElement.set(element);
    String projectPath = null;
    Set<String> scriptParameters = ContainerUtil.newLinkedHashSet();
    Set<String> tasksToRun = ContainerUtil.newLinkedHashSet();
    final Project project = context.getProject();
    final List<String> resolvedTests = ContainerUtil.newArrayList();
    for (String test : tests) {
        final int i = StringUtil.indexOf(test, ",");
        String aClass = i < 0 ? test : test.substring(0, i);
        final PsiClass psiClass = JavaPsiFacade.getInstance(project).findClass(aClass, GlobalSearchScope.projectScope(project));
        if (psiClass == null)
            continue;
        final PsiFile psiFile = psiClass.getContainingFile();
        if (psiFile == null)
            continue;
        final Module moduleForFile = ProjectFileIndex.SERVICE.getInstance(project).getModuleForFile(psiFile.getVirtualFile());
        if (!ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, moduleForFile))
            return false;
        projectPath = ExternalSystemApiUtil.getExternalRootProjectPath(moduleForFile);
        if (projectPath == null)
            return false;
        ContainerUtil.addAllNotNull(tasksToRun, getTasksToRun(moduleForFile));
        final String method = i != -1 && test.length() > i + 1 ? test.substring(i + 1) : null;
        scriptParameters.add(TestMethodGradleConfigurationProducer.createTestFilter(aClass, method));
        resolvedTests.add(psiClass.getName() + "," + (method == null ? "" : method));
    }
    if (tasksToRun.isEmpty() || projectPath == null)
        return false;
    configuration.getSettings().setExternalProjectPath(projectPath);
    configuration.getSettings().setTaskNames(ContainerUtil.newArrayList(tasksToRun));
    configuration.getSettings().setScriptParameters(StringUtil.join(scriptParameters, " "));
    final String name;
    if (resolvedTests.size() > 1) {
        name = resolvedTests.get(0) + " and " + (resolvedTests.size() - 1) + " more";
    } else {
        name = StringUtil.join(tests, "|");
    }
    configuration.setName(name);
    JavaRunConfigurationExtensionManager.getInstance().extendCreatedConfiguration(configuration, contextLocation);
    return true;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Project(com.intellij.openapi.project.Project) PsiClass(com.intellij.psi.PsiClass) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) 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