Search in sources :

Example 1 with ProjectPsiFilesUtils

use of org.stepik.plugin.utils.ProjectPsiFilesUtils in project intellij-plugins by StepicOrg.

the class AbstractMoveHandlerDelegate method doMove.

@Override
public void doMove(Project project, PsiElement[] elements, @Nullable PsiElement targetContainer, @Nullable MoveCallback callback) {
    List<PsiFileSystemItem> sources = Arrays.stream(elements).filter(psiElement -> isNotMovableOrRenameElement(psiElement, acceptableClasses)).map(ProjectPsiFilesUtils::getFile).filter(Objects::nonNull).collect(Collectors.toList());
    StringBuilder message = new StringBuilder();
    if (sources.size() > 1) {
        message.append("You can not move the following elements:");
    } else {
        PsiFileSystemItem source = sources.get(0);
        message.append("You can not move the ").append(source.isDirectory() ? "directory" : "file").append(":");
    }
    for (PsiFileSystemItem file : sources) {
        message.append("\n").append(file.getVirtualFile().getPath());
    }
    MessagesEx.error(project, message.toString(), "Move").showNow();
}
Also used : MoveHandlerDelegate(com.intellij.refactoring.move.MoveHandlerDelegate) Arrays(java.util.Arrays) ProjectPsiFilesUtils.isNotMovableOrRenameElement(org.stepik.plugin.utils.ProjectPsiFilesUtils.isNotMovableOrRenameElement) MoveCallback(com.intellij.refactoring.move.MoveCallback) MessagesEx(com.intellij.openapi.ui.ex.MessagesEx) Set(java.util.Set) Collectors(java.util.stream.Collectors) HashSet(java.util.HashSet) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) NotNull(org.jetbrains.annotations.NotNull) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) ProjectPsiFilesUtils.isCanNotBeTarget(org.stepik.plugin.utils.ProjectPsiFilesUtils.isCanNotBeTarget) ProjectPsiFilesUtils(org.stepik.plugin.utils.ProjectPsiFilesUtils) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) ProjectPsiFilesUtils(org.stepik.plugin.utils.ProjectPsiFilesUtils)

Aggregations

Project (com.intellij.openapi.project.Project)1 MessagesEx (com.intellij.openapi.ui.ex.MessagesEx)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFileSystemItem (com.intellij.psi.PsiFileSystemItem)1 MoveCallback (com.intellij.refactoring.move.MoveCallback)1 MoveHandlerDelegate (com.intellij.refactoring.move.MoveHandlerDelegate)1 Arrays (java.util.Arrays)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Objects (java.util.Objects)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1 ProjectPsiFilesUtils (org.stepik.plugin.utils.ProjectPsiFilesUtils)1 ProjectPsiFilesUtils.isCanNotBeTarget (org.stepik.plugin.utils.ProjectPsiFilesUtils.isCanNotBeTarget)1 ProjectPsiFilesUtils.isNotMovableOrRenameElement (org.stepik.plugin.utils.ProjectPsiFilesUtils.isNotMovableOrRenameElement)1