use of com.intellij.psi.PsiFileSystemItem 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.PsiFileSystemItem 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.PsiFileSystemItem in project intellij-community by JetBrains.
the class PyFindUsagesHandlerFactory method createFindUsagesHandler.
@Nullable
@Override
public FindUsagesHandler createFindUsagesHandler(@NotNull PsiElement element, boolean forHighlightUsages) {
if (element instanceof PyImportedModule) {
final PsiElement resolved = ((PyImportedModule) element).resolve();
if (resolved != null) {
element = resolved;
}
}
if (element instanceof PsiFileSystemItem) {
return new PyModuleFindUsagesHandler((PsiFileSystemItem) element);
}
if (element instanceof PyFunction) {
if (!forHighlightUsages) {
TypeEvalContext context = TypeEvalContext.userInitiated(element.getProject(), null);
final Collection<PsiElement> superMethods = PySuperMethodsSearch.search((PyFunction) element, true, context).findAll();
if (superMethods.size() > 0) {
final PsiElement next = superMethods.iterator().next();
// TODO should do this for Jython functions overriding Java methods too
if (next instanceof PyFunction && !isInObject((PyFunction) next)) {
int rc = Messages.showYesNoDialog(element.getProject(), "Method " + ((PyFunction) element).getName() + " overrides method of class " + ((PyFunction) next).getContainingClass().getName() + ".\nDo you want to find usages of the base method?", "Find Usages", Messages.getQuestionIcon());
if (rc == Messages.YES) {
List<PsiElement> allMethods = new ArrayList<>();
allMethods.add(element);
allMethods.addAll(superMethods);
return new PyFunctionFindUsagesHandler(element, allMethods);
} else {
return new PyFunctionFindUsagesHandler(element);
}
}
}
}
return new PyFunctionFindUsagesHandler(element);
}
if (element instanceof PyClass) {
return new PyClassFindUsagesHandler((PyClass) element);
}
if (element instanceof PyTargetExpression) {
return new PyTargetExpressionFindUsagesHandler(((PyTargetExpression) element));
}
return null;
}
use of com.intellij.psi.PsiFileSystemItem in project intellij-community by JetBrains.
the class DissociateResourceBundleAction method dissociate.
public static void dissociate(final Collection<ResourceBundle> resourceBundles, final Project project) {
final Set<PsiFileSystemItem> toUpdateInProjectView = new HashSet<>();
for (ResourceBundle resourceBundle : resourceBundles) {
for (final PropertiesFile propertiesFile : resourceBundle.getPropertiesFiles()) {
PsiDirectory containingDirectory = propertiesFile.getContainingFile().getContainingDirectory();
if (containingDirectory != null) {
toUpdateInProjectView.add(containingDirectory);
}
}
ResourceBundleManager.getInstance(project).dissociateResourceBundle(resourceBundle);
}
AbstractProjectViewPane currentProjectViewPane = ProjectView.getInstance(project).getCurrentProjectViewPane();
if (currentProjectViewPane == null) {
return;
}
AbstractTreeBuilder treeBuilder = currentProjectViewPane.getTreeBuilder();
if (treeBuilder != null) {
for (PsiFileSystemItem item : toUpdateInProjectView) {
treeBuilder.queueUpdateFrom(item, false);
}
}
}
use of com.intellij.psi.PsiFileSystemItem in project intellij-community by JetBrains.
the class CreatePackageAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
if (view == null) {
return;
}
final Project project = e.getData(CommonDataKeys.PROJECT);
final PsiDirectory directory = DirectoryChooserUtil.getOrChooseDirectory(view);
if (directory == null)
return;
final CreateDirectoryOrPackageHandler validator = new CreateDirectoryOrPackageHandler(project, directory, false, ".") {
@Override
protected void createDirectories(String subDirName) {
super.createDirectories(subDirName);
PsiFileSystemItem element = getCreatedElement();
if (element instanceof PsiDirectory) {
createInitPyInHierarchy((PsiDirectory) element, directory);
}
}
};
Messages.showInputDialog(project, IdeBundle.message("prompt.enter.new.package.name"), IdeBundle.message("title.new.package"), Messages.getQuestionIcon(), "", validator);
final PsiFileSystemItem result = validator.getCreatedElement();
if (result != null) {
view.selectElement(result);
}
}
Aggregations