mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
warn on
1. invoke create subclass in test root with selected destination - source 2. invoke create from usage in source root with selected destination - test 3. copy class from test root with selected destination - source
This commit is contained in:
+6
-1
@@ -296,7 +296,12 @@ public class CreateFromUsageUtils {
|
||||
Project project = manager.getProject();
|
||||
String title = QuickFixBundle.message("create.class.title", StringUtil.capitalize(classKind.getDescription()));
|
||||
|
||||
CreateClassDialog dialog = new CreateClassDialog(project, title, name, aPackage.getQualifiedName(), classKind, false, module);
|
||||
CreateClassDialog dialog = new CreateClassDialog(project, title, name, aPackage.getQualifiedName(), classKind, false, module){
|
||||
@Override
|
||||
protected boolean reportBaseInSourceSelectionInTest() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
dialog.show();
|
||||
if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) return null;
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.Pass;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
@@ -72,6 +73,16 @@ public class CreateClassDialog extends DialogWrapper {
|
||||
public String getTargetPackage() {
|
||||
return myPackageComponent.getText().trim();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean reportBaseInTestSelectionInSource() {
|
||||
return CreateClassDialog.this.reportBaseInTestSelectionInSource();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean reportBaseInSourceSelectionInTest() {
|
||||
return CreateClassDialog.this.reportBaseInSourceSelectionInTest();
|
||||
}
|
||||
};
|
||||
@NonNls private static final String RECENTS_KEY = "CreateClassDialog.RecentsKey";
|
||||
|
||||
@@ -102,7 +113,20 @@ public class CreateClassDialog extends DialogWrapper {
|
||||
}
|
||||
|
||||
myTfClassName.setText(myClassName);
|
||||
myDestinationCB.setData(myProject, myPackageComponent, getBaseDir(normalizedPackageName), ProjectRootManager.getInstance(myProject).getContentSourceRoots());
|
||||
myDestinationCB.setData(myProject, myPackageComponent, getBaseDir(normalizedPackageName), ProjectRootManager.getInstance(myProject).getContentSourceRoots(), new Pass<String>() {
|
||||
@Override
|
||||
public void pass(String s) {
|
||||
setErrorText(s);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected boolean reportBaseInTestSelectionInSource() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean reportBaseInSourceSelectionInTest() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected Action[] createActions() {
|
||||
|
||||
@@ -144,6 +144,11 @@ public class CreateSubclassAction extends BaseIntentionAction {
|
||||
protected PsiDirectory getBaseDir(String packageName) {
|
||||
return sourceDir;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean reportBaseInTestSelectionInSource() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
dialog.show();
|
||||
if (!dialog.isOK()) return null;
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.Pass;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.refactoring.HelpID;
|
||||
import com.intellij.refactoring.MoveDestination;
|
||||
@@ -58,6 +59,11 @@ class CopyClassDialog extends DialogWrapper{
|
||||
public String getTargetPackage() {
|
||||
return myTfPackage.getText().trim();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean reportBaseInTestSelectionInSource() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
public CopyClassDialog(PsiClass aClass, PsiDirectory defaultTargetDirectory, Project project, boolean doClone) {
|
||||
@@ -69,7 +75,13 @@ class CopyClassDialog extends DialogWrapper{
|
||||
RefactoringBundle.message("copy.class.copy.0.1", UsageViewUtil.getType(aClass), UsageViewUtil.getLongName(aClass));
|
||||
myInformationLabel.setText(text);
|
||||
init();
|
||||
myDestinationCB.setData(myProject, myTfPackage, defaultTargetDirectory, ProjectRootManager.getInstance(myProject).getContentSourceRoots());
|
||||
myDestinationCB.setData(myProject, myTfPackage, defaultTargetDirectory, ProjectRootManager.getInstance(myProject).getContentSourceRoots(),
|
||||
new Pass<String>() {
|
||||
@Override
|
||||
public void pass(String s) {
|
||||
setErrorText(s);
|
||||
}
|
||||
});
|
||||
myNameField.setText(UsageViewUtil.getShortName(aClass));
|
||||
}
|
||||
|
||||
|
||||
+41
-5
@@ -26,6 +26,7 @@ import com.intellij.openapi.project.ProjectUtil;
|
||||
import com.intellij.openapi.roots.ProjectFileIndex;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.ui.ComboBoxWithWidePopup;
|
||||
import com.intellij.openapi.util.Pass;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.psi.PsiManager;
|
||||
@@ -58,10 +59,19 @@ public abstract class DestinationFolderComboBox extends ComboboxWithBrowseButton
|
||||
|
||||
public abstract String getTargetPackage();
|
||||
|
||||
protected boolean reportBaseInTestSelectionInSource() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean reportBaseInSourceSelectionInTest() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setData(final Project project,
|
||||
final ReferenceEditorComboWithBrowseButton packageChooser,
|
||||
final PsiDirectory initialTargetDirectory,
|
||||
final VirtualFile[] sourceRoots) {
|
||||
final VirtualFile[] sourceRoots,
|
||||
final Pass<String> pass) {
|
||||
myInitialTargetDirectory = initialTargetDirectory;
|
||||
mySourceRoots = sourceRoots;
|
||||
new ComboboxSpeedSearch(getComboBox()) {
|
||||
@@ -115,17 +125,23 @@ public abstract class DestinationFolderComboBox extends ComboboxWithBrowseButton
|
||||
return;
|
||||
}
|
||||
}
|
||||
setComboboxModel(getComboBox(), root, fileIndex, sourceRoots, project, true);
|
||||
setComboboxModel(getComboBox(), root, fileIndex, sourceRoots, project, true, pass);
|
||||
}
|
||||
});
|
||||
|
||||
packageChooser.getChildComponent().addDocumentListener(new DocumentAdapter() {
|
||||
@Override
|
||||
public void documentChanged(DocumentEvent e) {
|
||||
setComboboxModel(getComboBox(), initialSourceRoot, fileIndex, sourceRoots, project, false);
|
||||
setComboboxModel(getComboBox(), initialSourceRoot, fileIndex, sourceRoots, project, false, pass);
|
||||
}
|
||||
});
|
||||
setComboboxModel(getComboBox(), initialSourceRoot, fileIndex, sourceRoots, project, false, pass);
|
||||
getComboBox().addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
updateErrorMessage(pass, fileIndex, getComboBox().getSelectedItem());
|
||||
}
|
||||
});
|
||||
setComboboxModel(getComboBox(), initialSourceRoot, fileIndex, sourceRoots, project, false);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -143,11 +159,30 @@ public abstract class DestinationFolderComboBox extends ComboboxWithBrowseButton
|
||||
return new AutocreatingSingleSourceRootMoveDestination(targetPackage, selectedDestination);
|
||||
}
|
||||
|
||||
private void updateErrorMessage(Pass<String> updateErrorMessage, ProjectFileIndex fileIndex, Object selectedItem) {
|
||||
updateErrorMessage.pass(null);
|
||||
if (myInitialTargetDirectory != null && selectedItem instanceof DirectoryChooser.ItemWrapper) {
|
||||
final PsiDirectory directory = ((DirectoryChooser.ItemWrapper)selectedItem).getDirectory();
|
||||
final boolean isSelectionInTestSourceContent = fileIndex.isInTestSourceContent(directory.getVirtualFile());
|
||||
final boolean inTestSourceContent = fileIndex.isInTestSourceContent(myInitialTargetDirectory.getVirtualFile());
|
||||
if (isSelectionInTestSourceContent != inTestSourceContent) {
|
||||
if (inTestSourceContent && reportBaseInTestSelectionInSource()) {
|
||||
updateErrorMessage.pass("Source root is selected while the test root is expected");
|
||||
}
|
||||
|
||||
if (isSelectionInTestSourceContent && reportBaseInSourceSelectionInTest()) {
|
||||
updateErrorMessage.pass("Test root is selected while the source root is expected");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setComboboxModel(JComboBox comboBox, VirtualFile initialTargetDirectorySourceRoot,
|
||||
ProjectFileIndex fileIndex,
|
||||
VirtualFile[] sourceRoots,
|
||||
Project project,
|
||||
boolean forceIncludeAll) {
|
||||
boolean forceIncludeAll,
|
||||
Pass<String> updateErrorMessage) {
|
||||
final LinkedHashSet<PsiDirectory> targetDirectories = new LinkedHashSet<PsiDirectory>();
|
||||
final HashMap<PsiDirectory, String> pathsToCreate = new HashMap<PsiDirectory, String>();
|
||||
MoveClassesOrPackagesUtil
|
||||
@@ -187,6 +222,7 @@ public abstract class DestinationFolderComboBox extends ComboboxWithBrowseButton
|
||||
}
|
||||
}
|
||||
}
|
||||
updateErrorMessage(updateErrorMessage, fileIndex, selection);
|
||||
comboBox.setModel(new CollectionComboBoxModel(items, selection));
|
||||
}
|
||||
|
||||
|
||||
+8
-1
@@ -27,6 +27,7 @@ import com.intellij.openapi.options.ConfigurationException;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.Pass;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.ProjectScope;
|
||||
@@ -258,7 +259,13 @@ public class MoveClassesOrPackagesDialog extends RefactoringDialog {
|
||||
myCbSearchInComments.setSelected(searchInComments);
|
||||
myCbSearchTextOccurences.setSelected(searchForTextOccurences);
|
||||
|
||||
((DestinationFolderComboBox)myDestinationFolderCB).setData(myProject, myClassPackageChooser, myInitialTargetDirectory, getSourceRoots());
|
||||
((DestinationFolderComboBox)myDestinationFolderCB).setData(myProject, myClassPackageChooser, myInitialTargetDirectory, getSourceRoots(),
|
||||
new Pass<String>() {
|
||||
@Override
|
||||
public void pass(String s) {
|
||||
setErrorText(s);
|
||||
}
|
||||
});
|
||||
UIUtil.setEnabled(myTargetPanel, getSourceRoots().length > 0 && isMoveToPackage() && !isTargetDirectoryFixed, true);
|
||||
validateButtons();
|
||||
myHelpID = helpID;
|
||||
|
||||
Reference in New Issue
Block a user