use of com.intellij.psi.PsiFileSystemItem in project intellij-community by JetBrains.
the class PyImportedModuleType method resolveMember.
@Nullable
@Override
public List<? extends RatedResolveResult> resolveMember(@NotNull String name, @Nullable PyExpression location, @NotNull AccessDirection direction, @NotNull PyResolveContext resolveContext) {
final PsiElement resolved = myImportedModule.resolve();
if (resolved != null) {
final PsiFile containingFile = location != null ? location.getContainingFile() : null;
List<PsiElement> elements = Collections.singletonList(ResolveImportUtil.resolveChild(resolved, name, containingFile, false, true, false));
final PyImportElement importElement = myImportedModule.getImportElement();
final PyFile resolvedFile = PyUtil.as(resolved, PyFile.class);
if (location != null && importElement != null && PyUtil.inSameFile(location, importElement) && ResolveImportUtil.getPointInImport(location) == PointInImport.NONE && resolved instanceof PsiFileSystemItem && (resolvedFile == null || !PyUtil.isPackage(resolvedFile) || resolvedFile.getElementNamed(name) == null)) {
final List<PsiElement> importedSubmodules = PyModuleType.collectImportedSubmodules((PsiFileSystemItem) resolved, location);
if (importedSubmodules != null) {
final Set<PsiElement> imported = Sets.newHashSet(importedSubmodules);
elements = ContainerUtil.filter(elements, element -> imported.contains(element));
}
}
return ResolveImportUtil.rateResults(elements);
}
return null;
}
use of com.intellij.psi.PsiFileSystemItem in project intellij-community by JetBrains.
the class FileListPasteProvider method performPaste.
@Override
public void performPaste(@NotNull DataContext dataContext) {
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
final IdeView ideView = LangDataKeys.IDE_VIEW.getData(dataContext);
if (project == null || ideView == null)
return;
if (!FileCopyPasteUtil.isFileListFlavorAvailable())
return;
final Transferable contents = CopyPasteManager.getInstance().getContents();
if (contents == null)
return;
final List<File> fileList = FileCopyPasteUtil.getFileList(contents);
if (fileList == null)
return;
if (DumbService.isDumb(project)) {
DumbService.getInstance(project).showDumbModeNotification("Sorry, file copy/paste is not available during indexing");
return;
}
final List<PsiElement> elements = new ArrayList<>();
for (File file : fileList) {
final VirtualFile vFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file);
if (vFile != null) {
final PsiManager instance = PsiManager.getInstance(project);
PsiFileSystemItem item = vFile.isDirectory() ? instance.findDirectory(vFile) : instance.findFile(vFile);
if (item != null) {
elements.add(item);
}
}
}
if (elements.size() > 0) {
final PsiDirectory dir = ideView.getOrChooseDirectory();
if (dir != null) {
final boolean move = LinuxDragAndDropSupport.isMoveOperation(contents);
if (move) {
new MoveFilesOrDirectoriesHandler().doMove(PsiUtilCore.toPsiElementArray(elements), dir);
} else {
new CopyFilesOrDirectoriesHandler().doCopy(PsiUtilCore.toPsiElementArray(elements), dir);
}
}
}
}
use of com.intellij.psi.PsiFileSystemItem in project intellij-community by JetBrains.
the class DeleteHandler method deletePsiElement.
public static void deletePsiElement(final PsiElement[] elementsToDelete, final Project project, boolean needConfirmation) {
if (elementsToDelete == null || elementsToDelete.length == 0)
return;
final PsiElement[] elements = PsiTreeUtil.filterAncestors(elementsToDelete);
boolean safeDeleteApplicable = true;
for (int i = 0; i < elements.length && safeDeleteApplicable; i++) {
PsiElement element = elements[i];
safeDeleteApplicable = SafeDeleteProcessor.validElement(element);
}
final boolean dumb = DumbService.getInstance(project).isDumb();
if (safeDeleteApplicable && !dumb) {
final Ref<Boolean> exit = Ref.create(false);
final SafeDeleteDialog dialog = new SafeDeleteDialog(project, elements, new SafeDeleteDialog.Callback() {
@Override
public void run(final SafeDeleteDialog dialog) {
if (!CommonRefactoringUtil.checkReadOnlyStatusRecursively(project, Arrays.asList(elements), true))
return;
SafeDeleteProcessor processor = SafeDeleteProcessor.createInstance(project, () -> {
exit.set(true);
dialog.close(DialogWrapper.OK_EXIT_CODE);
}, elements, dialog.isSearchInComments(), dialog.isSearchForTextOccurences(), true);
processor.run();
}
}) {
@Override
protected boolean isDelete() {
return true;
}
};
if (needConfirmation) {
dialog.setTitle(RefactoringBundle.message("delete.title"));
if (!dialog.showAndGet() || exit.get()) {
return;
}
}
} else {
@SuppressWarnings({ "UnresolvedPropertyKey" }) String warningMessage = DeleteUtil.generateWarningMessage(IdeBundle.message("prompt.delete.elements"), elements);
boolean anyDirectories = false;
String directoryName = null;
for (PsiElement psiElement : elementsToDelete) {
if (psiElement instanceof PsiDirectory && !PsiUtilBase.isSymLink((PsiDirectory) psiElement)) {
anyDirectories = true;
directoryName = ((PsiDirectory) psiElement).getName();
break;
}
}
if (anyDirectories) {
if (elements.length == 1) {
warningMessage += IdeBundle.message("warning.delete.all.files.and.subdirectories", directoryName);
} else {
warningMessage += IdeBundle.message("warning.delete.all.files.and.subdirectories.in.the.selected.directory");
}
}
if (safeDeleteApplicable && dumb) {
warningMessage += "\n\nWarning:\n Safe delete is not available while " + ApplicationNamesInfo.getInstance().getFullProductName() + " updates indices,\n no usages will be checked.";
}
if (needConfirmation) {
int result = Messages.showOkCancelDialog(project, warningMessage, IdeBundle.message("title.delete"), ApplicationBundle.message("button.delete"), CommonBundle.getCancelButtonText(), Messages.getQuestionIcon());
if (result != Messages.OK)
return;
}
}
CommandProcessor.getInstance().executeCommand(project, () -> NonProjectFileWritingAccessProvider.disableChecksDuring(() -> {
Collection<PsiElement> directories = ContainerUtil.newSmartList();
for (PsiElement e : elements) {
if (e instanceof PsiFileSystemItem && e.getParent() != null) {
directories.add(e.getParent());
}
}
if (!CommonRefactoringUtil.checkReadOnlyStatus(project, Arrays.asList(elements), directories, false)) {
return;
}
// deleted from project view or something like that.
if (CommonDataKeys.EDITOR.getData(DataManager.getInstance().getDataContext()) == null) {
CommandProcessor.getInstance().markCurrentCommandAsGlobal(project);
}
for (final PsiElement elementToDelete : elements) {
//was already deleted
if (!elementToDelete.isValid())
continue;
if (elementToDelete instanceof PsiDirectory) {
VirtualFile virtualFile = ((PsiDirectory) elementToDelete).getVirtualFile();
if (virtualFile.isInLocalFileSystem() && !virtualFile.is(VFileProperty.SYMLINK)) {
ArrayList<VirtualFile> readOnlyFiles = new ArrayList<>();
CommonRefactoringUtil.collectReadOnlyFiles(virtualFile, readOnlyFiles);
if (!readOnlyFiles.isEmpty()) {
String message = IdeBundle.message("prompt.directory.contains.read.only.files", virtualFile.getPresentableUrl());
int _result = Messages.showYesNoDialog(project, message, IdeBundle.message("title.delete"), Messages.getQuestionIcon());
if (_result != Messages.YES)
continue;
boolean success = true;
for (VirtualFile file : readOnlyFiles) {
success = clearReadOnlyFlag(file, project);
if (!success)
break;
}
if (!success)
continue;
}
}
} else if (!elementToDelete.isWritable() && !(elementToDelete instanceof PsiFileSystemItem && PsiUtilBase.isSymLink((PsiFileSystemItem) elementToDelete))) {
final PsiFile file = elementToDelete.getContainingFile();
if (file != null) {
final VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile.isInLocalFileSystem()) {
int _result = MessagesEx.fileIsReadOnly(project, virtualFile).setTitle(IdeBundle.message("title.delete")).appendMessage(" " + IdeBundle.message("prompt.delete.it.anyway")).askYesNo();
if (_result != Messages.YES)
continue;
boolean success = clearReadOnlyFlag(virtualFile, project);
if (!success)
continue;
}
}
}
try {
elementToDelete.checkDelete();
} catch (IncorrectOperationException ex) {
Messages.showMessageDialog(project, ex.getMessage(), CommonBundle.getErrorTitle(), Messages.getErrorIcon());
continue;
}
ApplicationManager.getApplication().runWriteAction(() -> {
try {
elementToDelete.delete();
} catch (final IncorrectOperationException ex) {
ApplicationManager.getApplication().invokeLater(() -> Messages.showMessageDialog(project, ex.getMessage(), CommonBundle.getErrorTitle(), Messages.getErrorIcon()));
}
});
}
}), RefactoringBundle.message("safe.delete.command", RefactoringUIUtil.calculatePsiElementDescriptionList(elements)), null);
}
use of com.intellij.psi.PsiFileSystemItem in project intellij-community by JetBrains.
the class ScopeViewPane method select.
@Override
public void select(Object element, VirtualFile file, boolean requestFocus) {
if (file == null)
return;
PsiFileSystemItem psiFile = file.isDirectory() ? PsiManager.getInstance(myProject).findDirectory(file) : PsiManager.getInstance(myProject).findFile(file);
if (psiFile == null)
return;
if (!(element instanceof PsiElement))
return;
List<NamedScope> allScopes = ContainerUtil.newArrayList(getShownScopes());
for (NamedScope scope : allScopes) {
String name = scope.getName();
if (name.equals(getSubId())) {
allScopes.remove(scope);
allScopes.add(0, scope);
break;
}
}
for (NamedScope scope : allScopes) {
String name = scope.getName();
PackageSet packageSet = scope.getValue();
if (packageSet == null)
continue;
if (changeView(packageSet, ((PsiElement) element), psiFile, name, myNamedScopeManager, requestFocus))
break;
if (changeView(packageSet, ((PsiElement) element), psiFile, name, myDependencyValidationManager, requestFocus))
break;
}
}
use of com.intellij.psi.PsiFileSystemItem in project intellij-community by JetBrains.
the class FileIncludeManagerImpl method doResolve.
@Nullable
private PsiFileSystemItem doResolve(@NotNull final FileIncludeInfo info, @NotNull final PsiFile context) {
if (info instanceof FileIncludeInfoImpl) {
String id = ((FileIncludeInfoImpl) info).providerId;
FileIncludeProvider provider = id == null ? null : myProviderMap.get(id);
final PsiFileSystemItem resolvedByProvider = provider == null ? null : provider.resolveIncludedFile(info, context);
if (resolvedByProvider != null) {
return resolvedByProvider;
}
}
PsiFileImpl psiFile = (PsiFileImpl) myPsiFileFactory.createFileFromText("dummy.txt", FileTypes.PLAIN_TEXT, info.path);
psiFile.setOriginalFile(context);
return new FileReferenceSet(psiFile) {
@Override
protected boolean useIncludingFileAsContext() {
return false;
}
}.resolve();
}
Aggregations