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