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 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 intellij-community by JetBrains.
the class PythonTestLegacyConfigurationProducer method isConfigurationFromContext.
@Override
public boolean isConfigurationFromContext(AbstractPythonLegacyTestRunConfiguration configuration, ConfigurationContext context) {
final Location location = context.getLocation();
if (location == null || !isAvailable(location))
return false;
final PsiElement element = location.getPsiElement();
final PsiFileSystemItem file = element.getContainingFile();
if (file == null)
return false;
final VirtualFile virtualFile = element instanceof PsiDirectory ? ((PsiDirectory) element).getVirtualFile() : file.getVirtualFile();
if (virtualFile == null)
return false;
final PyFunction pyFunction = PsiTreeUtil.getParentOfType(element, PyFunction.class, false);
final PyClass pyClass = PsiTreeUtil.getParentOfType(element, PyClass.class);
final AbstractPythonLegacyTestRunConfiguration.TestType confType = configuration.getTestType();
final String workingDirectory = configuration.getWorkingDirectory();
if (element instanceof PsiDirectory) {
final String path = ((PsiDirectory) element).getVirtualFile().getPath();
return confType == AbstractPythonLegacyTestRunConfiguration.TestType.TEST_FOLDER && path.equals(configuration.getFolderName()) || path.equals(new File(workingDirectory, configuration.getFolderName()).getAbsolutePath());
}
final String scriptName = configuration.getScriptName();
final String path = virtualFile.getPath();
final boolean isTestFileEquals = scriptName.equals(path) || path.equals(new File(workingDirectory, scriptName).getAbsolutePath());
if (pyFunction != null) {
final String methodName = configuration.getMethodName();
if (pyFunction.getContainingClass() == null) {
return confType == AbstractPythonLegacyTestRunConfiguration.TestType.TEST_FUNCTION && methodName.equals(pyFunction.getName()) && isTestFileEquals;
} else {
final String className = configuration.getClassName();
return confType == AbstractPythonLegacyTestRunConfiguration.TestType.TEST_METHOD && methodName.equals(pyFunction.getName()) && pyClass != null && className.equals(pyClass.getName()) && isTestFileEquals;
}
}
if (pyClass != null) {
final String className = configuration.getClassName();
return confType == AbstractPythonLegacyTestRunConfiguration.TestType.TEST_CLASS && className.equals(pyClass.getName()) && isTestFileEquals;
}
return confType == AbstractPythonLegacyTestRunConfiguration.TestType.TEST_SCRIPT && isTestFileEquals;
}
use of com.intellij.execution.Location 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.Location in project intellij-community by JetBrains.
the class PyTestConfigurationProducer method isConfigurationFromContext.
@Override
public boolean isConfigurationFromContext(AbstractPythonLegacyTestRunConfiguration configuration, ConfigurationContext context) {
final Location location = context.getLocation();
if (location == null)
return false;
if (!(configuration instanceof PyTestRunConfiguration))
return false;
final PsiElement element = location.getPsiElement();
final PsiFileSystemItem file = element instanceof PsiDirectory ? (PsiDirectory) element : element.getContainingFile();
if (file == null)
return false;
final VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile == null)
return false;
if (file instanceof PyFile || file instanceof PsiDirectory) {
final List<PyStatement> testCases = PyTestUtil.getPyTestCasesFromFile(file, TypeEvalContext.userInitiated(element.getProject(), element.getContainingFile()));
if (testCases.isEmpty())
return false;
} else {
return false;
}
final Sdk sdk = PythonSdkType.findPythonSdk(context.getModule());
if (sdk == null)
return false;
final String keywords = getKeywords(element, sdk);
final String scriptName = ((PyTestRunConfiguration) configuration).getTestToRun();
final String workingDirectory = configuration.getWorkingDirectory();
final String path = virtualFile.getPath();
final boolean isTestFileEquals = scriptName.equals(path) || path.equals(new File(workingDirectory, scriptName).getAbsolutePath());
final String configurationKeywords = ((PyTestRunConfiguration) configuration).getKeywords();
return isTestFileEquals && (configurationKeywords.equals(keywords) || StringUtil.isEmptyOrSpaces(((PyTestRunConfiguration) configuration).getKeywords()) && keywords == null);
}
Aggregations