Search in sources :

Example 91 with PsiDirectory

use of com.intellij.psi.PsiDirectory in project intellij-plugins by JetBrains.

the class FlexExtractSuperTest method performAction.

private void performAction(boolean classNotInterface, String from, final String extractedSuperName, int docCommentPolicy, JSExtractSuperProcessor.Mode mode, String[] members, String[] conflicts) {
    JSClass sourceClass = JSTestUtils.findClassByQName(from, GlobalSearchScope.moduleScope(myModule));
    final List<JSMemberInfo> memberInfos = FlexPullUpTest.getMemberInfos(members, sourceClass, false);
    JSMemberInfo.sortByOffset(memberInfos);
    JSMemberInfo[] infosArray = JSMemberInfo.getSelected(memberInfos, sourceClass, Conditions.alwaysTrue());
    try {
        final PsiElement finalSourceClass = sourceClass;
        PsiDirectory dir = WriteCommandAction.runWriteCommandAction(null, (Computable<PsiDirectory>) () -> ActionScriptCreateClassOrInterfaceFix.findOrCreateDirectory(StringUtil.getPackageName(extractedSuperName), finalSourceClass));
        new JSExtractSuperProcessor(sourceClass, infosArray, StringUtil.getShortName(extractedSuperName), StringUtil.getPackageName(extractedSuperName), docCommentPolicy, mode, classNotInterface, dir).run();
        assertEquals("Conflicts expected:\n" + StringUtil.join(conflicts, "\n"), 0, conflicts.length);
        myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
        FileDocumentManager.getInstance().saveAllDocuments();
    } catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
        assertNotNull("Conflicts not expected but found:" + e.getMessage(), conflicts);
        assertSameElements(e.getMessages(), conflicts);
        myDoCompare = false;
    }
}
Also used : PostprocessReformattingAspect(com.intellij.psi.impl.source.PostprocessReformattingAspect) BaseRefactoringProcessor(com.intellij.refactoring.BaseRefactoringProcessor) PsiDirectory(com.intellij.psi.PsiDirectory) JSExtractSuperProcessor(com.intellij.lang.javascript.refactoring.extractSuper.JSExtractSuperProcessor) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) JSMemberInfo(com.intellij.lang.javascript.refactoring.util.JSMemberInfo) PsiElement(com.intellij.psi.PsiElement)

Example 92 with PsiDirectory

use of com.intellij.psi.PsiDirectory in project intellij-plugins by JetBrains.

the class FlexMoveClassDialog method doAction.

@Override
protected void doAction() {
    myTargetPackageField.updateRecents();
    PsiElement firstElement = myElements.iterator().next();
    PsiDirectory baseDir;
    if (myTargetContainer instanceof PsiDirectory) {
        baseDir = (PsiDirectory) myTargetContainer;
    } else {
        baseDir = PlatformPackageUtil.getDirectory(firstElement);
    }
    String nameToCheck = myFileLocal ? myClassNameField.getText() : null;
    PsiDirectory targetDirectory = JSRefactoringUtil.chooseOrCreateDirectoryForClass(myProject, ModuleUtilCore.findModuleForPsiElement(firstElement), GlobalSearchScope.projectScope(myProject), myTargetPackageField.getText(), nameToCheck, baseDir, myCbMoveToAnotherSourceFolder.isSelected() ? ThreeState.YES : ThreeState.NO);
    if (targetDirectory == null) {
        return;
    }
    // file-local case already checked by JSRefactoringUtil.chooseOrCreateDirectoryForClass (see nameToCheck)
    if (!myFileLocal) {
        try {
            for (PsiElement element : myElements) {
                MoveFilesOrDirectoriesUtil.checkMove(element.getContainingFile(), targetDirectory);
            }
        } catch (IncorrectOperationException e) {
            CommonRefactoringUtil.showErrorMessage(RefactoringBundle.message("error.title"), e.getMessage(), getHelpId(), myProject);
            return;
        }
    }
    BaseRefactoringProcessor processor;
    if (myFileLocal) {
        processor = new FlexMoveInnerClassProcessor(myElements.iterator().next(), targetDirectory, myClassNameField.getText(), myTargetPackageField.getText(), myCbSearchInComments.isSelected(), myCbSearchTextOccurences.isSelected(), myCallback);
    } else {
        processor = new FlexMoveClassProcessor(myElements, targetDirectory, myTargetPackageField.getText(), myCbSearchInComments.isSelected(), myCbSearchTextOccurences.isSelected(), myCallback);
    }
    invokeRefactoring(processor);
}
Also used : BaseRefactoringProcessor(com.intellij.refactoring.BaseRefactoringProcessor) PsiDirectory(com.intellij.psi.PsiDirectory) IncorrectOperationException(com.intellij.util.IncorrectOperationException) PsiElement(com.intellij.psi.PsiElement)

Example 93 with PsiDirectory

use of com.intellij.psi.PsiDirectory in project intellij-plugins by JetBrains.

the class DartRunConfigurationBase method getRefactoringElementListener.

@Nullable
@Override
public RefactoringElementListener getRefactoringElementListener(final PsiElement element) {
    if (!(element instanceof PsiFileSystemItem))
        return null;
    final String filePath = getRunnerParameters().getFilePath();
    final VirtualFile file = filePath == null ? null : ((PsiFileSystemItem) element).getVirtualFile();
    if (file == null)
        return null;
    final String affectedPath = file.getPath();
    if (element instanceof PsiFile) {
        if (filePath.equals(affectedPath)) {
            return new RenameRefactoringListener(affectedPath);
        }
    }
    if (element instanceof PsiDirectory) {
        if (filePath.startsWith(affectedPath + "/")) {
            return new RenameRefactoringListener(affectedPath);
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiDirectory(com.intellij.psi.PsiDirectory) PsiFile(com.intellij.psi.PsiFile) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) Nullable(org.jetbrains.annotations.Nullable)

Example 94 with PsiDirectory

use of com.intellij.psi.PsiDirectory in project intellij-plugins by JetBrains.

the class NewActionScriptClassAction method isAvailable.

private boolean isAvailable(DataContext dataContext) {
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
    if (project == null || project.isDisposed() || view == null)
        return false;
    ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    for (PsiDirectory dir : view.getDirectories()) {
        if (projectFileIndex.isInSourceContent(dir.getVirtualFile()) && DirectoryIndex.getInstance(dir.getProject()).getPackageName(dir.getVirtualFile()) != null) {
            Module module = ModuleUtilCore.findModuleForPsiElement(dir);
            if (module != null && isAvailableIn(module)) {
                return true;
            }
        }
    }
    return false;
}
Also used : Project(com.intellij.openapi.project.Project) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) PsiDirectory(com.intellij.psi.PsiDirectory) IdeView(com.intellij.ide.IdeView) Module(com.intellij.openapi.module.Module)

Example 95 with PsiDirectory

use of com.intellij.psi.PsiDirectory in project intellij-plugins by JetBrains.

the class NewActionScriptClassAction method actionPerformed.

public void actionPerformed(final AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();
    final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
    if (view == null) {
        return;
    }
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    final PsiDirectory dir = view.getOrChooseDirectory();
    if (dir == null || project == null)
        return;
    CommandProcessor.getInstance().executeCommand(project, () -> createAction(dir).execute(), getCommandName(), null);
}
Also used : Project(com.intellij.openapi.project.Project) PsiDirectory(com.intellij.psi.PsiDirectory) IdeView(com.intellij.ide.IdeView)

Aggregations

PsiDirectory (com.intellij.psi.PsiDirectory)321 VirtualFile (com.intellij.openapi.vfs.VirtualFile)122 PsiFile (com.intellij.psi.PsiFile)111 PsiElement (com.intellij.psi.PsiElement)79 Project (com.intellij.openapi.project.Project)73 Module (com.intellij.openapi.module.Module)68 Nullable (org.jetbrains.annotations.Nullable)62 NotNull (org.jetbrains.annotations.NotNull)50 IdeView (com.intellij.ide.IdeView)31 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)24 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)24 PsiManager (com.intellij.psi.PsiManager)24 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)20 ArrayList (java.util.ArrayList)20 PsiPackage (com.intellij.psi.PsiPackage)17 File (java.io.File)15 PsiFileSystemItem (com.intellij.psi.PsiFileSystemItem)11 IncorrectOperationException (com.intellij.util.IncorrectOperationException)11 Course (com.jetbrains.edu.learning.courseFormat.Course)11 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)10