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)));
}
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;
}
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;
}
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;
}
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)));
}
Aggregations