Search in sources :

Example 6 with Location

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

the class TestMethods method getTestPresentation.

@Nullable
public static String getTestPresentation(AbstractTestProxy testInfo, Project project, GlobalSearchScope searchScope) {
    final Location location = testInfo.getLocation(project, searchScope);
    final PsiElement element = location != null ? location.getPsiElement() : null;
    if (element instanceof PsiMethod) {
        final PsiClass containingClass = location instanceof MethodLocation ? ((MethodLocation) location).getContainingClass() : location instanceof PsiMemberParameterizedLocation ? ((PsiMemberParameterizedLocation) location).getContainingClass() : ((PsiMethod) element).getContainingClass();
        if (containingClass != null) {
            final String proxyName = testInfo.getName();
            final String methodName = ((PsiMethod) element).getName();
            return JavaExecutionUtil.getRuntimeQualifiedName(containingClass) + "," + (proxyName.contains(methodName) ? proxyName.substring(proxyName.indexOf(methodName)) : methodName);
        }
    }
    return null;
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) MethodLocation(com.intellij.execution.junit2.info.MethodLocation) PsiElement(com.intellij.psi.PsiElement) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation) MethodLocation(com.intellij.execution.junit2.info.MethodLocation) Location(com.intellij.execution.Location) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with Location

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

the class PyCCRunTestsConfigurationProducer method getTestPath.

@Nullable
private static String getTestPath(@NotNull ConfigurationContext context) {
    Location location = context.getLocation();
    if (location == null) {
        return null;
    }
    VirtualFile file = location.getVirtualFile();
    if (file == null) {
        return null;
    }
    VirtualFile taskDir = StudyUtils.getTaskDir(file);
    if (taskDir == null) {
        return null;
    }
    Task task = StudyUtils.getTask(location.getProject(), taskDir);
    if (task == null) {
        return null;
    }
    String testsFileName = PyCCLanguageManager.getSubtaskTestsFileName(task.getActiveSubtaskIndex());
    String taskDirPath = FileUtil.toSystemDependentName(taskDir.getPath());
    String testsPath = taskDir.findChild(EduNames.SRC) != null ? FileUtil.join(taskDirPath, EduNames.SRC, testsFileName) : FileUtil.join(taskDirPath, testsFileName);
    String filePath = FileUtil.toSystemDependentName(file.getPath());
    return filePath.equals(testsPath) ? testsPath : null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Task(com.jetbrains.edu.learning.courseFormat.Task) Location(com.intellij.execution.Location) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with Location

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

the class KotlinTestNgConfigurationProducer method setupConfigurationFromContext.

@Override
protected boolean setupConfigurationFromContext(TestNGConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    // TODO: check TestNG Pattern running first, before method/class (see TestNGInClassConfigurationProducer for logic)
    // TODO: and PsiClassOwner not handled, which is in TestNGInClassConfigurationProducer
    Location location = context.getLocation();
    if (location == null) {
        return false;
    }
    Project project = context.getProject();
    PsiElement leaf = location.getPsiElement();
    if (!ProjectRootsUtil.isInProjectOrLibSource(leaf)) {
        return false;
    }
    if (!(leaf.getContainingFile() instanceof KtFile)) {
        return false;
    }
    KtFile ktFile = (KtFile) leaf.getContainingFile();
    if (TargetPlatformDetector.getPlatform(ktFile) != JvmPlatform.INSTANCE) {
        return false;
    }
    KtNamedDeclaration declarationToRun = getDeclarationToRun(leaf);
    if (declarationToRun instanceof KtNamedFunction) {
        KtNamedFunction function = (KtNamedFunction) declarationToRun;
        @SuppressWarnings("unchecked") KtElement owner = PsiTreeUtil.getParentOfType(function, KtFunction.class, KtClass.class);
        if (owner instanceof KtClass) {
            PsiClass delegate = toLightClass((KtClass) owner);
            if (delegate != null) {
                for (PsiMethod method : delegate.getMethods()) {
                    if (method.getNavigationElement() == function) {
                        if (TestNGUtil.hasTest(method)) {
                            return configure(configuration, location, context, project, delegate, method);
                        }
                        break;
                    }
                }
            }
        }
    }
    if (declarationToRun instanceof KtClass) {
        PsiClass delegate = toLightClass((KtClassOrObject) declarationToRun);
        if (!isTestNGClass(delegate)) {
            return false;
        }
        return configure(configuration, location, context, project, delegate, null);
    }
    return false;
}
Also used : Project(com.intellij.openapi.project.Project) PsiLocation(com.intellij.execution.PsiLocation) MethodLocation(com.intellij.execution.junit2.info.MethodLocation) Location(com.intellij.execution.Location)

Example 9 with Location

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

the class ConfigurationContext method createConfiguration.

private void createConfiguration() {
    LOG.assertTrue(myConfiguration == null);
    final Location location = getLocation();
    myConfiguration = location != null && !DumbService.isDumb(location.getProject()) ? PreferredProducerFind.createConfiguration(location, this) : null;
    myInitialized = true;
}
Also used : PsiLocation(com.intellij.execution.PsiLocation) Location(com.intellij.execution.Location)

Example 10 with Location

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

the class AbstractApplicationConfigurationProducer method setupConfigurationFromContext.

@Override
protected boolean setupConfigurationFromContext(T configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    final Location contextLocation = context.getLocation();
    if (contextLocation == null) {
        return false;
    }
    final Location location = JavaExecutionUtil.stepIntoSingleClass(contextLocation);
    if (location == null) {
        return false;
    }
    final PsiElement element = location.getPsiElement();
    if (!element.isPhysical()) {
        return false;
    }
    PsiElement currentElement = element;
    PsiMethod method;
    while ((method = findMain(currentElement)) != null) {
        final PsiClass aClass = method.getContainingClass();
        if (ConfigurationUtil.MAIN_CLASS.value(aClass)) {
            sourceElement.set(method);
            setupConfiguration(configuration, aClass, context);
            return true;
        }
        currentElement = method.getParent();
    }
    final PsiClass aClass = ApplicationConfigurationType.getMainClass(element);
    if (aClass == null) {
        return false;
    }
    sourceElement.set(aClass);
    setupConfiguration(configuration, aClass, context);
    return true;
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) PsiElement(com.intellij.psi.PsiElement) Location(com.intellij.execution.Location)

Aggregations

Location (com.intellij.execution.Location)62 PsiElement (com.intellij.psi.PsiElement)20 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