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;
}
}
Aggregations