Search in sources :

Example 66 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 67 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 68 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 69 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)

Example 70 with Location

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

the class PyStudyRunContextAction method update.

@Override
public void update(AnActionEvent event) {
    final ConfigurationContext context = ConfigurationContext.getFromContext(event.getDataContext());
    final Location location = context.getLocation();
    if (location == null)
        return;
    super.update(event);
    final InputEvent inputEvent = event.getInputEvent();
    final Presentation presentation = event.getPresentation();
    if (inputEvent == null && !(context.getDataContext().getData(PlatformDataKeys.CONTEXT_COMPONENT) instanceof EditorGutter)) {
        presentation.setText("");
    }
}
Also used : ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) EditorGutter(com.intellij.openapi.editor.EditorGutter) InputEvent(java.awt.event.InputEvent) Presentation(com.intellij.openapi.actionSystem.Presentation) Location(com.intellij.execution.Location)

Aggregations

Location (com.intellij.execution.Location)79 PsiClass (com.intellij.psi.PsiClass)27 PsiElement (com.intellij.psi.PsiElement)26 VirtualFile (com.intellij.openapi.vfs.VirtualFile)20 PsiMethod (com.intellij.psi.PsiMethod)19 PsiLocation (com.intellij.execution.PsiLocation)18 Project (com.intellij.openapi.project.Project)18 PsiMemberParameterizedLocation (com.intellij.execution.junit2.PsiMemberParameterizedLocation)17 MethodLocation (com.intellij.execution.junit2.info.MethodLocation)16 Module (com.intellij.openapi.module.Module)14 Nullable (org.jetbrains.annotations.Nullable)9 PsiFile (com.intellij.psi.PsiFile)8 ArrayList (java.util.ArrayList)8 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)7 SMTestProxy (com.intellij.execution.testframework.sm.runner.SMTestProxy)6 NotNull (org.jetbrains.annotations.NotNull)6 Nullable (javax.annotation.Nullable)5 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)4 PatternConfigurationProducer (com.intellij.execution.junit.PatternConfigurationProducer)4 Kind (com.google.idea.blaze.base.model.primitives.Kind)3