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