Search in sources :

Example 1 with FlexMoveInnerClassProcessor

use of com.intellij.javascript.flex.refactoring.moveClass.FlexMoveInnerClassProcessor in project intellij-plugins by JetBrains.

the class FlexMoveInnerClassTest method performAction.

private void performAction(VirtualFile rootDir, String fromFilePath, String className, final String targetPackage, boolean searchInStringsAndComments, boolean searchTextOccurences, String[] conflicts) {
    PsiFile sourceFile = myPsiManager.findFile(rootDir.findFileByRelativePath(fromFilePath));
    final EditorInfo editorInfo = new EditorInfo(sourceFile.getText());
    assertEquals("Wrong number of carets", 1, editorInfo.caretState.carets.size());
    assertNotNull("No caret specified", editorInfo.caretState.carets.get(0).position);
    final Document doc = PsiDocumentManager.getInstance(myProject).getDocument(sourceFile);
    final PsiDirectory targetDirectory = WriteAction.compute(() -> {
        doc.setText(editorInfo.getNewFileText());
        PsiDocumentManager.getInstance(myProject).commitDocument(doc);
        final VirtualFile srcRootFile = ModuleRootManager.getInstance(myModule).getSourceRoots()[0];
        final VirtualFile file = VfsUtilCore.findRelativeFile(targetPackage.replace('.', File.separatorChar), srcRootFile);
        if (file != null) {
            return myPsiManager.findDirectory(file);
        } else {
            PsiDirectory srcRoot = myPsiManager.findDirectory(srcRootFile);
            return DirectoryUtil.createSubdirectories(targetPackage, srcRoot, ".");
        }
    });
    PsiElement element = sourceFile.findElementAt(editorInfo.caretState.carets.get(0).getCaretOffset(doc));
    while (true) {
        assertFalse("inner element to move not found", element instanceof JSFile);
        final JSQualifiedNamedElement adjusted = FlexMoveFileRefactoringHandler.adjustForMove(element);
        if (adjusted != null) {
            element = adjusted;
            break;
        }
        element = element.getParent();
    }
    try {
        new FlexMoveInnerClassProcessor((JSQualifiedNamedElement) element, targetDirectory, className, targetPackage, searchInStringsAndComments, searchTextOccurences, null).run();
        assertEquals("Conflicts expected:\n" + StringUtil.join(conflicts, "\n"), 0, conflicts.length);
    } catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
        assertTrue("Conflicts not expected but found:" + e.getMessage(), conflicts.length > 0);
        assertSameElements(e.getMessages(), conflicts);
        myDoCompare = false;
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FlexMoveInnerClassProcessor(com.intellij.javascript.flex.refactoring.moveClass.FlexMoveInnerClassProcessor) BaseRefactoringProcessor(com.intellij.refactoring.BaseRefactoringProcessor) EditorInfo(com.intellij.codeInsight.EditorInfo) PsiDirectory(com.intellij.psi.PsiDirectory) JSQualifiedNamedElement(com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement) PsiFile(com.intellij.psi.PsiFile) Document(com.intellij.openapi.editor.Document) JSFile(com.intellij.lang.javascript.psi.JSFile) PsiElement(com.intellij.psi.PsiElement)

Aggregations

EditorInfo (com.intellij.codeInsight.EditorInfo)1 FlexMoveInnerClassProcessor (com.intellij.javascript.flex.refactoring.moveClass.FlexMoveInnerClassProcessor)1 JSFile (com.intellij.lang.javascript.psi.JSFile)1 JSQualifiedNamedElement (com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement)1 Document (com.intellij.openapi.editor.Document)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiDirectory (com.intellij.psi.PsiDirectory)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 BaseRefactoringProcessor (com.intellij.refactoring.BaseRefactoringProcessor)1