use of com.intellij.psi.PsiDirectory in project intellij-community by JetBrains.
the class PyTestConfigurationProducer method setupConfigurationFromContext.
@Override
protected boolean setupConfigurationFromContext(AbstractPythonLegacyTestRunConfiguration<PyTestRunConfiguration> configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
final PsiElement element = sourceElement.get();
final Module module = ModuleUtilCore.findModuleForPsiElement(element);
if (!(configuration instanceof PyTestRunConfiguration)) {
return false;
}
if (module == null) {
return false;
}
if (!(TestRunnerService.getInstance(module).getProjectConfiguration().equals(PythonTestConfigurationsModel.PY_TEST_NAME))) {
return false;
}
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;
}
configuration.setUseModuleSdk(true);
configuration.setModule(ModuleUtilCore.findModuleForPsiElement(element));
((PyTestRunConfiguration) configuration).setTestToRun(virtualFile.getPath());
final String keywords = getKeywords(element, sdk);
if (keywords != null) {
((PyTestRunConfiguration) configuration).useKeyword(true);
((PyTestRunConfiguration) configuration).setKeywords(keywords);
configuration.setName("py.test in " + keywords);
} else {
configuration.setName("py.test in " + file.getName());
}
return true;
}
use of com.intellij.psi.PsiDirectory 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);
}
use of com.intellij.psi.PsiDirectory in project intellij-community by JetBrains.
the class PropertiesImplUtil method createByUrl.
@Nullable
public static ResourceBundle createByUrl(@NotNull final String url, @NotNull final Project project) {
final int idx = url.lastIndexOf('/');
if (idx == -1)
return null;
final String baseDirectoryName = url.substring(0, idx);
final String baseName = url.substring(idx + 1);
final VirtualFile baseDirectoryVirtualFile = VirtualFileManager.getInstance().findFileByUrl(baseDirectoryName);
if (baseDirectoryVirtualFile == null) {
return null;
}
final PsiDirectory baseDirectory = PsiManager.getInstance(project).findDirectory(baseDirectoryVirtualFile);
if (baseDirectory == null) {
return null;
}
final ResourceBundleManager bundleBaseNameManager = ResourceBundleManager.getInstance(project);
for (PsiFile file : baseDirectory.getFiles()) {
final PropertiesFile propertiesFile = getPropertiesFile(file);
if (propertiesFile == null)
continue;
final String currBaseName = bundleBaseNameManager.getBaseName(file);
if (currBaseName.equals(baseName)) {
return getResourceBundle(propertiesFile);
}
}
return null;
}
use of com.intellij.psi.PsiDirectory in project intellij-community by JetBrains.
the class AbstractFolderNode method containsImpl.
@Override
protected boolean containsImpl(@NotNull final VirtualFile file) {
final PsiElement psiElement = extractPsiFromValue();
if (psiElement == null || !psiElement.isValid()) {
return false;
}
final VirtualFile valueFile = ((PsiDirectory) psiElement).getVirtualFile();
if (!VfsUtil.isAncestor(valueFile, file, false)) {
return false;
}
final Project project = psiElement.getProject();
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
final Module module = fileIndex.getModuleForFile(valueFile);
if (module == null) {
return fileIndex.getModuleForFile(file) == null;
}
return ModuleRootManager.getInstance(module).getFileIndex().isInContent(file);
}
use of com.intellij.psi.PsiDirectory in project intellij-community by JetBrains.
the class AbstractFolderNode method getChildrenImpl.
@Override
@Nullable
protected Collection<AbstractTreeNode> getChildrenImpl() {
final PsiDirectory directory = getPsiDirectory();
if (!directory.isValid()) {
return Collections.emptyList();
}
// scan folder's children
final List<AbstractTreeNode> children = Arrays.stream(directory.getSubdirectories()).map(this::createFolderNode).collect(Collectors.toList());
for (PsiFile file : directory.getFiles()) {
processNotDirectoryFile(children, file);
}
return children;
}
Aggregations