mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
root chooser: wrap return value
This commit is contained in:
+14
-1
@@ -28,10 +28,13 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import com.intellij.refactoring.HelpID;
|
||||
import com.intellij.refactoring.PackageWrapper;
|
||||
import com.intellij.refactoring.RefactorJBundle;
|
||||
import com.intellij.refactoring.RefactoringBundle;
|
||||
import com.intellij.refactoring.move.moveClassesOrPackages.DestinationFolderComboBox;
|
||||
import com.intellij.refactoring.ui.PackageNameReferenceEditorCombo;
|
||||
import com.intellij.refactoring.ui.RefactoringDialog;
|
||||
import com.intellij.ui.ComboboxWithBrowseButton;
|
||||
import com.intellij.ui.DocumentAdapter;
|
||||
import com.intellij.ui.ReferenceEditorComboWithBrowseButton;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
@@ -64,6 +67,7 @@ class WrapReturnValueDialog extends RefactoringDialog {
|
||||
private JRadioButton myCreateInnerClassButton;
|
||||
private JTextField myInnerClassNameTextField;
|
||||
private JPanel myCreateInnerPanel;
|
||||
private ComboboxWithBrowseButton myDestinationCb;
|
||||
private static final String RECENT_KEYS = "WrapReturnValue.RECENT_KEYS";
|
||||
|
||||
WrapReturnValueDialog(PsiMethod sourceMethod) {
|
||||
@@ -96,7 +100,8 @@ class WrapReturnValueDialog extends RefactoringDialog {
|
||||
packageName = getPackageName();
|
||||
}
|
||||
invokeRefactoring(
|
||||
new WrapReturnValueProcessor(className, packageName, sourceMethod, useExistingClass, createInnerClass, (PsiField)myFieldsCombo.getSelectedItem()));
|
||||
new WrapReturnValueProcessor(className, packageName, ((DestinationFolderComboBox)myDestinationCb).selectDirectory(new PackageWrapper(sourceMethod.getManager(), packageName), false),
|
||||
sourceMethod, useExistingClass, createInnerClass, (PsiField)myFieldsCombo.getSelectedItem()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -278,5 +283,13 @@ class WrapReturnValueDialog extends RefactoringDialog {
|
||||
}
|
||||
}, "", PsiManager.getInstance(myProject), true, RECENT_KEYS);
|
||||
existingClassField.getChildComponent().getDocument().addDocumentListener(adapter);
|
||||
|
||||
myDestinationCb = new DestinationFolderComboBox() {
|
||||
@Override
|
||||
public String getTargetPackage() {
|
||||
return getPackageName();
|
||||
}
|
||||
};
|
||||
((DestinationFolderComboBox)myDestinationCb).setData(myProject, sourceMethod.getContainingFile().getContainingDirectory(), packageTextField.getChildComponent());
|
||||
}
|
||||
}
|
||||
|
||||
+16
-2
@@ -3,7 +3,7 @@
|
||||
<grid id="27dc6" binding="myWholePanel" layout-manager="GridLayoutManager" row-count="9" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="404" height="321"/>
|
||||
<xy x="20" y="20" width="404" height="351"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
@@ -24,7 +24,7 @@
|
||||
<text value="&Use existing class"/>
|
||||
</properties>
|
||||
</component>
|
||||
<grid id="1eeb1" binding="myNewClassPanel" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="1eeb1" binding="myNewClassPanel" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="20" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
@@ -63,6 +63,20 @@
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="56018" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Target destination"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="cf692" class="com.intellij.ui.ComboboxWithBrowseButton" binding="myDestinationCb" custom-create="true">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="ab530" binding="myExistingClassPanel" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
|
||||
+14
-3
@@ -31,6 +31,7 @@ import com.intellij.psi.search.searches.OverridingMethodsSearch;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import com.intellij.refactoring.MoveDestination;
|
||||
import com.intellij.refactoring.RefactorJBundle;
|
||||
import com.intellij.refactoring.psi.PropertyUtils;
|
||||
import com.intellij.refactoring.psi.TypeParametersVisitor;
|
||||
@@ -58,6 +59,7 @@ public class WrapReturnValueProcessor extends FixableUsagesRefactoringProcessor
|
||||
|
||||
private static final Logger LOG = Logger.getInstance("com.siyeh.rpp.wrapreturnvalue.WrapReturnValueProcessor");
|
||||
|
||||
private MoveDestination myMoveDestination;
|
||||
private final PsiMethod method;
|
||||
private final String className;
|
||||
private final String packageName;
|
||||
@@ -71,10 +73,11 @@ public class WrapReturnValueProcessor extends FixableUsagesRefactoringProcessor
|
||||
|
||||
public WrapReturnValueProcessor(String className,
|
||||
String packageName,
|
||||
PsiMethod method,
|
||||
MoveDestination moveDestination, PsiMethod method,
|
||||
boolean useExistingClass,
|
||||
final boolean createInnerClass, PsiField delegateField) {
|
||||
super(method.getProject());
|
||||
myMoveDestination = moveDestination;
|
||||
this.method = method;
|
||||
this.className = className;
|
||||
this.packageName = packageName;
|
||||
@@ -227,6 +230,9 @@ public class WrapReturnValueProcessor extends FixableUsagesRefactoringProcessor
|
||||
if (existingClass != null) {
|
||||
conflicts.putValue(existingClass, RefactorJBundle.message("there.already.exists.a.class.with.the.selected.name"));
|
||||
}
|
||||
if (myMoveDestination != null && !myMoveDestination.isTargetAccessible(myProject, method.getContainingFile().getVirtualFile())) {
|
||||
conflicts.putValue(method, "Created class won't be accessible in the call place");
|
||||
}
|
||||
}
|
||||
return showConflicts(conflicts, refUsages.get());
|
||||
}
|
||||
@@ -268,8 +274,13 @@ public class WrapReturnValueProcessor extends FixableUsagesRefactoringProcessor
|
||||
final PsiFile containingFile = method.getContainingFile();
|
||||
|
||||
final PsiDirectory containingDirectory = containingFile.getContainingDirectory();
|
||||
final Module module = ModuleUtil.findModuleForPsiElement(containingFile);
|
||||
final PsiDirectory directory = PackageUtil.findOrCreateDirectoryForPackage(module, packageName, containingDirectory, true, true);
|
||||
final PsiDirectory directory;
|
||||
if (myMoveDestination != null) {
|
||||
directory = myMoveDestination.getTargetDirectory(containingDirectory);
|
||||
} else {
|
||||
final Module module = ModuleUtil.findModuleForPsiElement(containingFile);
|
||||
directory = PackageUtil.findOrCreateDirectoryForPackage(module, packageName, containingDirectory, true, true);
|
||||
}
|
||||
|
||||
if (directory != null) {
|
||||
final PsiElement shortenedFile = JavaCodeStyleManager.getInstance(project).shortenClassReferences(psiFile);
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
*/
|
||||
package com.intellij.refactoring;
|
||||
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiField;
|
||||
@@ -53,7 +51,8 @@ public class WrapReturnValueTest extends MultiFileTestCase{
|
||||
|
||||
assertTrue(!existing || wrapperClass != null);
|
||||
final PsiField delegateField = existing ? wrapperClass.findFieldByName("myField", false) : null;
|
||||
WrapReturnValueProcessor processor = new WrapReturnValueProcessor(wrapperClassName, "", method, existing, createInnerClass,
|
||||
WrapReturnValueProcessor processor = new WrapReturnValueProcessor(wrapperClassName, "",
|
||||
null, method, existing, createInnerClass,
|
||||
delegateField);
|
||||
processor.run();
|
||||
/*LocalFileSystem.getInstance().refresh(false);
|
||||
|
||||
Reference in New Issue
Block a user