Search in sources :

Example 1 with PsiLocation

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

the class ConfigurationsTest method testCreateFromContext.

@Test
public void testCreateFromContext() {
    final Project project = myProjectFixture.getProject();
    final PsiClass psiClass = findTestClass(project);
    final TestNGInClassConfigurationProducer producer = new TestNGInClassConfigurationProducer();
    final MapDataContext dataContext = new MapDataContext();
    dataContext.put(CommonDataKeys.PROJECT, project);
    dataContext.put(LangDataKeys.MODULE, ModuleUtil.findModuleForPsiElement(psiClass));
    dataContext.put(Location.DATA_KEY, PsiLocation.fromPsiElement(psiClass));
    final ConfigurationFromContext fromContext = producer.createConfigurationFromContext(ConfigurationContext.getFromContext(dataContext));
    assert fromContext != null;
    final RunnerAndConfigurationSettings config = fromContext.getConfigurationSettings();
    final RunConfiguration runConfiguration = config.getConfiguration();
    Assert.assertTrue(runConfiguration instanceof TestNGConfiguration);
    TestNGConfigurationType t = (TestNGConfigurationType) runConfiguration.getType();
    Assert.assertTrue(t.isConfigurationByLocation(runConfiguration, new PsiLocation(project, psiClass)));
}
Also used : Project(com.intellij.openapi.project.Project) MapDataContext(com.intellij.testFramework.MapDataContext) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) PsiClass(com.intellij.psi.PsiClass) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) PsiLocation(com.intellij.execution.PsiLocation) Test(org.testng.annotations.Test)

Example 2 with PsiLocation

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

the class PyToxTestLocator method getLocation.

@NotNull
@Override
public List<Location> getLocation(@NotNull final String protocol, @NotNull final String path, @NotNull final Project project, @NotNull final GlobalSearchScope scope) {
    final PsiFile file = PyElementGenerator.getInstance(project).createDummyFile(LanguageLevel.PYTHON24, DUMMY_FILE_PADDING);
    file.putUserData(ENV_NAME_KEY, path);
    @SuppressWarnings("unchecked") final List<Location> locations = Collections.singletonList(new PsiLocation(file));
    return locations;
}
Also used : PsiFile(com.intellij.psi.PsiFile) PsiLocation(com.intellij.execution.PsiLocation) PsiLocation(com.intellij.execution.PsiLocation) Location(com.intellij.execution.Location) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with PsiLocation

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

the class GradleUrlProvider method getLocation.

@NotNull
@Override
public List<Location> getLocation(@NotNull String protocol, @NotNull String path, @NotNull Project project, @NotNull GlobalSearchScope scope) {
    if (!PROTOCOL_ID.equals(protocol))
        return Collections.emptyList();
    final String className = extractFullClassName(path);
    if (className == null)
        return Collections.emptyList();
    final PsiClass testClass = JavaPsiFacade.getInstance(project).findClass(className, GlobalSearchScope.allScope(project));
    if (testClass == null)
        return Collections.emptyList();
    final String methodName = extractMethodName(path);
    if (methodName == null) {
        return Collections.<Location>singletonList(new PsiLocation<>(project, testClass));
    }
    final PsiMethod[] methods = testClass.findMethodsByName(methodName, true);
    final List<Location> list = new ArrayList<>(methods.length);
    for (PsiMethod method : methods) {
        list.add(new PsiLocation<>(project, method));
    }
    return list;
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) ArrayList(java.util.ArrayList) PsiLocation(com.intellij.execution.PsiLocation) Location(com.intellij.execution.Location) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with PsiLocation

use of com.intellij.execution.PsiLocation 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 5 with PsiLocation

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

the class ConfigurationsTest method testReuseOrCreateNewConfiguration.

@Test
public void testReuseOrCreateNewConfiguration() {
    final Project project = myProjectFixture.getProject();
    final PsiClass psiClass = findTestClass(project);
    final TestNGConfiguration configuration = createConfiguration(project);
    final TestNGConfigurationType type = (TestNGConfigurationType) configuration.getFactory().getType();
    //class config
    configuration.beClassConfiguration(psiClass);
    PsiMethod testMethod = findTestMethod(psiClass);
    Assert.assertTrue(type.isConfigurationByLocation(configuration, new PsiLocation(project, psiClass)));
    Assert.assertFalse(type.isConfigurationByLocation(configuration, new PsiLocation(project, testMethod)));
    //method config
    configuration.beMethodConfiguration(new PsiLocation<>(project, testMethod));
    Assert.assertTrue(type.isConfigurationByLocation(configuration, new PsiLocation(project, testMethod)));
    Assert.assertFalse(type.isConfigurationByLocation(configuration, new PsiLocation(project, psiClass)));
}
Also used : Project(com.intellij.openapi.project.Project) PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) PsiLocation(com.intellij.execution.PsiLocation) Test(org.testng.annotations.Test)

Aggregations

PsiLocation (com.intellij.execution.PsiLocation)9 Location (com.intellij.execution.Location)6 PsiClass (com.intellij.psi.PsiClass)4 PsiFile (com.intellij.psi.PsiFile)3 PsiMethod (com.intellij.psi.PsiMethod)3 Nullable (org.jetbrains.annotations.Nullable)3 Project (com.intellij.openapi.project.Project)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PsiElement (com.intellij.psi.PsiElement)2 NotNull (org.jetbrains.annotations.NotNull)2 Test (org.testng.annotations.Test)2 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)1 ConfigurationFromContext (com.intellij.execution.actions.ConfigurationFromContext)1 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)1 PsiMemberParameterizedLocation (com.intellij.execution.junit2.PsiMemberParameterizedLocation)1 MethodLocation (com.intellij.execution.junit2.info.MethodLocation)1 StackTraceLine (com.intellij.execution.stacktrace.StackTraceLine)1 LineTokenizer (com.intellij.openapi.diff.LineTokenizer)1 Document (com.intellij.openapi.editor.Document)1 MapDataContext (com.intellij.testFramework.MapDataContext)1