Search in sources :

Example 56 with Location

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

the class AbstractInClassConfigurationProducer method setupConfigurationFromContext.

protected boolean setupConfigurationFromContext(T configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    if (isMultipleElementsSelected(context)) {
        return false;
    }
    final Location contextLocation = context.getLocation();
    setupConfigurationParamName(configuration, contextLocation);
    PsiClass psiClass = null;
    PsiElement element = context.getPsiLocation();
    while (element != null) {
        if (element instanceof PsiClass && isTestClass((PsiClass) element)) {
            psiClass = (PsiClass) element;
            break;
        } else if (element instanceof PsiMember) {
            psiClass = contextLocation instanceof MethodLocation ? ((MethodLocation) contextLocation).getContainingClass() : ((PsiMember) element).getContainingClass();
            if (isTestClass(psiClass)) {
                break;
            }
        } else if (element instanceof PsiClassOwner) {
            final PsiClass[] classes = ((PsiClassOwner) element).getClasses();
            if (classes.length == 1) {
                psiClass = classes[0];
                break;
            }
        }
        element = element.getParent();
    }
    if (!isTestClass(psiClass))
        return false;
    PsiElement psiElement = psiClass;
    final Project project = context.getProject();
    RunnerAndConfigurationSettings settings = cloneTemplateConfiguration(context);
    setupConfigurationModule(context, configuration);
    final Module originalModule = configuration.getConfigurationModule().getModule();
    configuration.beClassConfiguration(psiClass);
    PsiMethod method = PsiTreeUtil.getParentOfType(context.getPsiLocation(), PsiMethod.class, false);
    while (method != null) {
        if (isTestMethod(false, method)) {
            configuration.beMethodConfiguration(MethodLocation.elementInClass(method, psiClass));
            psiElement = method;
        }
        method = PsiTreeUtil.getParentOfType(method, PsiMethod.class);
    }
    configuration.restoreOriginalModule(originalModule);
    settings.setName(configuration.getName());
    sourceElement.set(psiElement);
    return true;
}
Also used : Project(com.intellij.openapi.project.Project) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) MethodLocation(com.intellij.execution.junit2.info.MethodLocation) Module(com.intellij.openapi.module.Module) PsiLocation(com.intellij.execution.PsiLocation) MethodLocation(com.intellij.execution.junit2.info.MethodLocation) Location(com.intellij.execution.Location)

Example 57 with Location

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

the class JavaAwareTestConsoleProperties method getErrorNavigatable.

@Nullable
@Override
public Navigatable getErrorNavigatable(@NotNull Location<?> location, @NotNull String stacktrace) {
    //navigate to the first stack trace
    final String[] stackTrace = new LineTokenizer(stacktrace).execute();
    final PsiLocation<?> psiLocation = location.toPsiLocation();
    final PsiClass containingClass = psiLocation.getParentElement(PsiClass.class);
    if (containingClass == null)
        return null;
    final String qualifiedName = containingClass.getQualifiedName();
    if (qualifiedName == null)
        return null;
    String containingMethod = null;
    for (Iterator<Location<PsiMethod>> iterator = psiLocation.getAncestors(PsiMethod.class, false); iterator.hasNext(); ) {
        final PsiMethod psiMethod = iterator.next().getPsiElement();
        if (containingClass.equals(psiMethod.getContainingClass()))
            containingMethod = psiMethod.getName();
    }
    if (containingMethod == null)
        return null;
    StackTraceLine lastLine = null;
    for (String aStackTrace : stackTrace) {
        final StackTraceLine line = new StackTraceLine(containingClass.getProject(), aStackTrace);
        if (containingMethod.equals(line.getMethodName()) && qualifiedName.equals(line.getClassName())) {
            lastLine = line;
            break;
        }
    }
    return lastLine != null ? lastLine.getOpenFileDescriptor(containingClass.getContainingFile().getVirtualFile()) : null;
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) StackTraceLine(com.intellij.execution.stacktrace.StackTraceLine) LineTokenizer(com.intellij.openapi.diff.LineTokenizer) PsiClass(com.intellij.psi.PsiClass) PsiLocation(com.intellij.execution.PsiLocation) Location(com.intellij.execution.Location) Nullable(org.jetbrains.annotations.Nullable)

Example 58 with Location

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

the class JarApplicationConfigurationProducer method getJarFileFromContext.

@Nullable
private static VirtualFile getJarFileFromContext(ConfigurationContext context) {
    Location location = context.getLocation();
    if (location == null)
        return null;
    VirtualFile file = location.getVirtualFile();
    return file != null && FileUtilRt.extensionEquals(file.getName(), "jar") ? file : null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Location(com.intellij.execution.Location) Nullable(org.jetbrains.annotations.Nullable)

Example 59 with Location

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

the class PythonRunConfigurationProducer method setupConfigurationFromContext.

@Override
protected boolean setupConfigurationFromContext(PythonRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    final Location location = context.getLocation();
    if (location == null)
        return false;
    final PsiFile script = location.getPsiElement().getContainingFile();
    if (!isAvailable(location, script))
        return false;
    final VirtualFile vFile = script.getVirtualFile();
    if (vFile == null)
        return false;
    configuration.setScriptName(vFile.getPath());
    final VirtualFile parent = vFile.getParent();
    if (parent != null) {
        configuration.setWorkingDirectory(parent.getPath());
    }
    final Module module = ModuleUtilCore.findModuleForPsiElement(script);
    if (module != null) {
        configuration.setUseModuleSdk(true);
        configuration.setModule(module);
    }
    configuration.setName(configuration.suggestedName());
    return true;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) Location(com.intellij.execution.Location)

Example 60 with Location

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

the class PythonRunConfigurationProducer method isConfigurationFromContext.

@Override
public boolean isConfigurationFromContext(PythonRunConfiguration configuration, ConfigurationContext context) {
    final Location location = context.getLocation();
    if (location == null)
        return false;
    final PsiFile script = location.getPsiElement().getContainingFile();
    if (!isAvailable(location, script))
        return false;
    final VirtualFile virtualFile = script.getVirtualFile();
    if (virtualFile == null)
        return false;
    if (virtualFile instanceof LightVirtualFile)
        return false;
    final String workingDirectory = configuration.getWorkingDirectory();
    final String scriptName = configuration.getScriptName();
    final String path = virtualFile.getPath();
    return scriptName.equals(path) || path.equals(new File(workingDirectory, scriptName).getAbsolutePath());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) PsiFile(com.intellij.psi.PsiFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) PsiFile(com.intellij.psi.PsiFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) 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