mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
show refactoring conflicts in usage view
This commit is contained in:
+9
-6
@@ -301,7 +301,7 @@ public class ChangeSignatureProcessor extends BaseRefactoringProcessor {
|
||||
myChangeInfo.updateMethod((PsiMethod) elements[0]);
|
||||
}
|
||||
|
||||
private void addMethodConflicts(Collection<String> conflicts) {
|
||||
private void addMethodConflicts(Map<PsiElement, String> conflicts) {
|
||||
String newMethodName = myChangeInfo.newName;
|
||||
|
||||
try {
|
||||
@@ -338,10 +338,10 @@ public class ChangeSignatureProcessor extends BaseRefactoringProcessor {
|
||||
|
||||
|
||||
protected boolean preprocessUsages(Ref<UsageInfo[]> refUsages) {
|
||||
Set<String> conflictDescriptions = new HashSet<String>();
|
||||
Map<PsiElement, String> conflictDescriptions = new HashMap<PsiElement, String>();
|
||||
UsageInfo[] usagesIn = refUsages.get();
|
||||
addMethodConflicts(conflictDescriptions);
|
||||
conflictDescriptions.addAll(RenameUtil.getConflictDescriptions(usagesIn));
|
||||
conflictDescriptions.putAll(RenameUtil.getConflictDescriptions(usagesIn));
|
||||
Set<UsageInfo> usagesSet = new HashSet<UsageInfo>(Arrays.asList(usagesIn));
|
||||
RenameUtil.removeConflictUsages(usagesSet);
|
||||
if (myChangeInfo.isVisibilityChanged) {
|
||||
@@ -356,7 +356,10 @@ public class ChangeSignatureProcessor extends BaseRefactoringProcessor {
|
||||
if (myPrepareSuccessfulSwingThreadCallback != null && !conflictDescriptions.isEmpty()) {
|
||||
ConflictsDialog dialog = new ConflictsDialog(myProject, conflictDescriptions);
|
||||
dialog.show();
|
||||
if (!dialog.isOK()) return false;
|
||||
if (!dialog.isOK()){
|
||||
if (dialog.isShowConflicts()) prepareSuccessful();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (myChangeInfo.isReturnTypeChanged) {
|
||||
@@ -368,7 +371,7 @@ public class ChangeSignatureProcessor extends BaseRefactoringProcessor {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void addInaccessibilityDescriptions(Set<UsageInfo> usages, Set<String> conflictDescriptions) throws IncorrectOperationException {
|
||||
private void addInaccessibilityDescriptions(Set<UsageInfo> usages, Map<PsiElement, String> conflictDescriptions) throws IncorrectOperationException {
|
||||
PsiMethod method = myChangeInfo.getMethod();
|
||||
PsiModifierList modifierList = (PsiModifierList)method.getModifierList().copy();
|
||||
RefactoringUtil.setVisibility(modifierList, myNewVisibility);
|
||||
@@ -391,7 +394,7 @@ public class ChangeSignatureProcessor extends BaseRefactoringProcessor {
|
||||
RefactoringUIUtil.getDescription(method, true),
|
||||
myNewVisibility,
|
||||
RefactoringUIUtil.getDescription(ConflictsUtil.getContainer(element), true));
|
||||
conflictDescriptions.add(message);
|
||||
conflictDescriptions.put(method, message);
|
||||
if (!needToChangeCalls()) {
|
||||
iterator.remove();
|
||||
}
|
||||
|
||||
+9
-9
@@ -117,20 +117,20 @@ public class ConvertToInstanceMethodProcessor extends BaseRefactoringProcessor {
|
||||
|
||||
protected boolean preprocessUsages(Ref<UsageInfo[]> refUsages) {
|
||||
UsageInfo[] usagesIn = refUsages.get();
|
||||
ArrayList<String> conflicts = new ArrayList<String>();
|
||||
Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
|
||||
final Set<PsiMember> methods = Collections.singleton((PsiMember)myMethod);
|
||||
if (!myTargetClass.isInterface()) {
|
||||
final String original = VisibilityUtil.getVisibilityModifier(myMethod.getModifierList());
|
||||
conflicts.addAll(
|
||||
Arrays.asList(MoveMembersProcessor.analyzeAccessibilityConflicts(methods, myTargetClass, new LinkedHashSet<String>(), original)));
|
||||
conflicts.putAll(
|
||||
MoveMembersProcessor.analyzeAccessibilityConflicts(methods, myTargetClass, new LinkedHashMap<PsiElement, String>(), original));
|
||||
}
|
||||
else {
|
||||
for (final UsageInfo usage : usagesIn) {
|
||||
if (usage instanceof ImplementingClassUsageInfo) {
|
||||
conflicts.addAll(Arrays.asList(MoveMembersProcessor.analyzeAccessibilityConflicts(methods,
|
||||
conflicts.putAll(MoveMembersProcessor.analyzeAccessibilityConflicts(methods,
|
||||
((ImplementingClassUsageInfo)usage).getPsiClass(),
|
||||
new LinkedHashSet<String>(),
|
||||
PsiModifier.PUBLIC)));
|
||||
new LinkedHashMap<PsiElement, String>(),
|
||||
PsiModifier.PUBLIC));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -147,7 +147,7 @@ public class ConvertToInstanceMethodProcessor extends BaseRefactoringProcessor {
|
||||
String message = RefactoringBundle.message("0.contains.call.with.null.argument.for.parameter.1",
|
||||
RefactoringUIUtil.getDescription(ConflictsUtil.getContainer(methodCall), true),
|
||||
CommonRefactoringUtil.htmlEmphasize(myTargetParameter.getName()));
|
||||
conflicts.add(message);
|
||||
conflicts.put(methodCall, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -163,7 +163,7 @@ public class ConvertToInstanceMethodProcessor extends BaseRefactoringProcessor {
|
||||
return showConflicts(conflicts);
|
||||
}
|
||||
|
||||
private void addInaccessibilityConflicts(final UsageInfo[] usages, final ArrayList<String> conflicts) throws IncorrectOperationException {
|
||||
private void addInaccessibilityConflicts(final UsageInfo[] usages, final Map<PsiElement, String> conflicts) throws IncorrectOperationException {
|
||||
final PsiModifierList copy = (PsiModifierList)myMethod.getModifierList().copy();
|
||||
if (myNewVisibility != null) {
|
||||
if (myNewVisibility.equals(VisibilityUtil.ESCALATE_VISIBILITY)) {
|
||||
@@ -191,7 +191,7 @@ public class ConvertToInstanceMethodProcessor extends BaseRefactoringProcessor {
|
||||
String message = RefactoringBundle.message("0.with.1.visibility.is.not.accesible.from.2",
|
||||
RefactoringUIUtil.getDescription(myMethod, true), newVisibility,
|
||||
RefactoringUIUtil.getDescription(ConflictsUtil.getContainer(call), true));
|
||||
conflicts.add(message);
|
||||
conflicts.put(myMethod, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-4
@@ -70,7 +70,7 @@ public class EncapsulateFieldsProcessor extends BaseRefactoringProcessor {
|
||||
}
|
||||
|
||||
protected boolean preprocessUsages(Ref<UsageInfo[]> refUsages) {
|
||||
ArrayList<String> conflicts = new ArrayList<String>();
|
||||
Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
|
||||
|
||||
if (myDialog != null) {
|
||||
checkExistingMethods(myDialog.getGetterPrototypes(), conflicts, true);
|
||||
@@ -79,7 +79,10 @@ public class EncapsulateFieldsProcessor extends BaseRefactoringProcessor {
|
||||
if(conflicts.size() > 0) {
|
||||
ConflictsDialog dialog = new ConflictsDialog(myProject, conflicts);
|
||||
dialog.show();
|
||||
if(!dialog.isOK()) return false;
|
||||
if(!dialog.isOK()){
|
||||
if (dialog.isShowConflicts()) prepareSuccessful();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +90,7 @@ public class EncapsulateFieldsProcessor extends BaseRefactoringProcessor {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void checkExistingMethods(PsiMethod[] prototypes, ArrayList<String> conflicts, boolean isGetter) {
|
||||
private void checkExistingMethods(PsiMethod[] prototypes, Map<PsiElement, String> conflicts, boolean isGetter) {
|
||||
if(prototypes == null) return;
|
||||
for (PsiMethod prototype : prototypes) {
|
||||
final PsiType prototypeReturnType = prototype.getReturnType();
|
||||
@@ -105,7 +108,7 @@ public class EncapsulateFieldsProcessor extends BaseRefactoringProcessor {
|
||||
CommonRefactoringUtil.htmlEmphasize(prototype.getName())) :
|
||||
RefactoringBundle.message("encapsulate.fields.setter.exists", CommonRefactoringUtil.htmlEmphasize(descr),
|
||||
CommonRefactoringUtil.htmlEmphasize(prototype.getName()));
|
||||
conflicts.add(message);
|
||||
conflicts.put(existing, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,11 @@ import com.intellij.refactoring.ui.ConflictsDialog;
|
||||
import com.intellij.refactoring.ui.VisibilityPanel;
|
||||
import com.intellij.refactoring.util.ConflictsUtil;
|
||||
import com.intellij.refactoring.util.ParameterTablePanel;
|
||||
import com.intellij.util.VisibilityUtil;
|
||||
import com.intellij.ui.EditorTextField;
|
||||
import com.intellij.ui.IdeBorderFactory;
|
||||
import com.intellij.ui.NonFocusableCheckBox;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import com.intellij.util.VisibilityUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -27,8 +26,8 @@ import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class ExtractMethodDialog extends AbstractExtractDialog {
|
||||
@@ -148,12 +147,15 @@ public class ExtractMethodDialog extends AbstractExtractDialog {
|
||||
}
|
||||
|
||||
protected void doOKAction() {
|
||||
Set<String> conflicts = new HashSet<String>();
|
||||
Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
|
||||
checkMethodConflicts(conflicts);
|
||||
if (!conflicts.isEmpty()) {
|
||||
final ConflictsDialog conflictsDialog = new ConflictsDialog(myProject, conflicts);
|
||||
conflictsDialog.show();
|
||||
if (!conflictsDialog.isOK()) return;
|
||||
if (!conflictsDialog.isOK()){
|
||||
if (conflictsDialog.isShowConflicts()) close(CANCEL_EXIT_CODE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (myCbMakeVarargs != null && myCbMakeVarargs.isSelected()) {
|
||||
@@ -394,7 +396,7 @@ public class ExtractMethodDialog extends AbstractExtractDialog {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
protected void checkMethodConflicts(Collection<String> conflicts) {
|
||||
protected void checkMethodConflicts(Map<PsiElement, String> conflicts) {
|
||||
PsiMethod prototype;
|
||||
try {
|
||||
PsiElementFactory factory = JavaPsiFacade.getInstance(myProject).getElementFactory();
|
||||
|
||||
+11
-7
@@ -12,10 +12,9 @@ import com.intellij.refactoring.extractMethod.AbstractExtractDialog;
|
||||
import com.intellij.refactoring.extractMethod.InputVariables;
|
||||
import com.intellij.refactoring.ui.ConflictsDialog;
|
||||
import com.intellij.refactoring.util.ParameterTablePanel;
|
||||
import com.intellij.util.VisibilityUtil;
|
||||
import com.intellij.ui.EditorTextField;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import com.intellij.util.VisibilityUtil;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
@@ -24,7 +23,8 @@ import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Set;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class ExtractMethodObjectDialog extends AbstractExtractDialog {
|
||||
@@ -132,16 +132,20 @@ public class ExtractMethodObjectDialog extends AbstractExtractDialog {
|
||||
}
|
||||
|
||||
protected void doOKAction() {
|
||||
Set<String> conflicts = new HashSet<String>();
|
||||
Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
|
||||
if (myCreateInnerClassRb.isSelected()) {
|
||||
if (myTargetClass.findInnerClassByName(myInnerClassName.getText(), false) != null) {
|
||||
conflicts.add("Inner class " + myInnerClassName.getText() + " already defined in class " + myTargetClass.getName());
|
||||
final PsiClass innerClass = myTargetClass.findInnerClassByName(myInnerClassName.getText(), false);
|
||||
if (innerClass != null) {
|
||||
conflicts.put(innerClass, "Inner class " + myInnerClassName.getText() + " already defined in class " + myTargetClass.getName());
|
||||
}
|
||||
}
|
||||
if (conflicts.size() > 0) {
|
||||
final ConflictsDialog conflictsDialog = new ConflictsDialog(myProject, conflicts);
|
||||
conflictsDialog.show();
|
||||
if (!conflictsDialog.isOK()) return;
|
||||
if (!conflictsDialog.isOK()){
|
||||
if (conflictsDialog.isShowConflicts()) close(CANCEL_EXIT_CODE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
final JCheckBox makeVarargsCb = myCreateInnerClassRb.isSelected() ? myCbMakeVarargs : myCbMakeVarargsAnonymous;
|
||||
|
||||
+7
-3
@@ -14,6 +14,7 @@ import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.ScrollType;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.refactoring.HelpID;
|
||||
import com.intellij.refactoring.RefactoringActionHandler;
|
||||
@@ -30,6 +31,7 @@ import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
public class ExtractSuperclassHandler implements RefactoringActionHandler, ExtractSuperclassDialog.Callback, ElementsHandler {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.extractSuperclass.ExtractSuperclassHandler");
|
||||
@@ -115,12 +117,14 @@ public class ExtractSuperclassHandler implements RefactoringActionHandler, Extra
|
||||
else {
|
||||
targetPackage = null;
|
||||
}
|
||||
String[] conflicts =
|
||||
LinkedHashMap<PsiElement,String> conflicts =
|
||||
PullUpConflictsUtil.checkConflicts(infos, mySubclass, null, targetPackage, targetDirectory, dialog.getContainmentVerifier());
|
||||
if (conflicts.length > 0) {
|
||||
if (!conflicts.isEmpty()) {
|
||||
ConflictsDialog conflictsDialog = new ConflictsDialog(myProject, conflicts);
|
||||
conflictsDialog.show();
|
||||
return conflictsDialog.isOK();
|
||||
final boolean ok = conflictsDialog.isOK();
|
||||
if (!ok && conflictsDialog.isShowConflicts()) dialog.close(DialogWrapper.CANCEL_EXIT_CODE);
|
||||
return ok;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
+11
-11
@@ -97,18 +97,18 @@ public class ExtractClassProcessor extends FixableUsagesRefactoringProcessor {
|
||||
|
||||
@Override
|
||||
protected boolean preprocessUsages(final Ref<UsageInfo[]> refUsages) {
|
||||
final List<String> conflicts = new ArrayList<String>();
|
||||
final Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
|
||||
final Project project = sourceClass.getProject();
|
||||
final GlobalSearchScope scope = GlobalSearchScope.allScope(project);
|
||||
final PsiClass existingClass =
|
||||
JavaPsiFacade.getInstance(project).findClass(StringUtil.getQualifiedName(newPackageName, newClassName), scope);
|
||||
if (existingClass != null) {
|
||||
conflicts.add(RefactorJBundle.message("cannot.perform.the.refactoring") +
|
||||
conflicts.put(existingClass, RefactorJBundle.message("cannot.perform.the.refactoring") +
|
||||
RefactorJBundle.message("there.already.exists.a.class.with.the.chosen.name"));
|
||||
}
|
||||
|
||||
if (!myGenerateAccessors) {
|
||||
conflicts.addAll(calculateInitializersConflicts());
|
||||
conflicts.putAll(calculateInitializersConflicts());
|
||||
final NecessaryAccessorsVisitor visitor = new NecessaryAccessorsVisitor();
|
||||
for (PsiField field : fields) {
|
||||
field.accept(visitor);
|
||||
@@ -122,35 +122,35 @@ public class ExtractClassProcessor extends FixableUsagesRefactoringProcessor {
|
||||
|
||||
final Set<PsiField> fieldsNeedingGetter = visitor.getFieldsNeedingGetter();
|
||||
for (PsiField field : fieldsNeedingGetter) {
|
||||
conflicts.add("Field \'" + field.getName() + "\' needs getter");
|
||||
conflicts.put(field, "Field \'" + field.getName() + "\' needs getter");
|
||||
}
|
||||
final Set<PsiField> fieldsNeedingSetter = visitor.getFieldsNeedingSetter();
|
||||
for (PsiField field : fieldsNeedingSetter) {
|
||||
conflicts.add("Field \'" + field.getName() + "\' needs getter");
|
||||
conflicts.put(field, "Field \'" + field.getName() + "\' needs getter");
|
||||
}
|
||||
}
|
||||
return showConflicts(conflicts);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean showConflicts(final List<String> conflicts) {
|
||||
protected boolean showConflicts(final Map<PsiElement, String> conflicts) {
|
||||
if (!conflicts.isEmpty() && ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
throw new RuntimeException(StringUtil.join(conflicts, "\n"));
|
||||
throw new RuntimeException(StringUtil.join(conflicts.values(), "\n"));
|
||||
}
|
||||
return super.showConflicts(conflicts);
|
||||
}
|
||||
|
||||
private List<String> calculateInitializersConflicts() {
|
||||
final List<String> out = new ArrayList<String>();
|
||||
private Map<PsiElement, String> calculateInitializersConflicts() {
|
||||
final Map<PsiElement, String> out = new HashMap<PsiElement, String>();
|
||||
final PsiClassInitializer[] initializers = sourceClass.getInitializers();
|
||||
for (PsiClassInitializer initializer : initializers) {
|
||||
if (initializerDependsOnMoved(initializer)) {
|
||||
out.add("Class initializer requires moved members");
|
||||
out.put(initializer, "Class initializer requires moved members");
|
||||
}
|
||||
}
|
||||
for (PsiMethod constructor : sourceClass.getConstructors()) {
|
||||
if (initializerDependsOnMoved(constructor.getBody())) {
|
||||
out.add("Constructor requires moved members");
|
||||
out.put(constructor, "Constructor requires moved members");
|
||||
}
|
||||
}
|
||||
return out;
|
||||
|
||||
+5
-4
@@ -19,8 +19,9 @@ import com.intellij.usageView.UsageViewUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author ven
|
||||
@@ -169,7 +170,7 @@ class InlineConstantFieldProcessor extends BaseRefactoringProcessor {
|
||||
|
||||
protected boolean preprocessUsages(Ref<UsageInfo[]> refUsages) {
|
||||
UsageInfo[] usagesIn = refUsages.get();
|
||||
ArrayList<String> conflicts = new ArrayList<String>();
|
||||
Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
|
||||
|
||||
ReferencedElementsCollector collector = new ReferencedElementsCollector();
|
||||
PsiExpression initializer = myField.getInitializer();
|
||||
@@ -183,14 +184,14 @@ class InlineConstantFieldProcessor extends BaseRefactoringProcessor {
|
||||
if (element instanceof PsiExpression && isAccessedForWriting((PsiExpression)element)) {
|
||||
String message = RefactoringBundle.message("0.is.used.for.writing.in.1", RefactoringUIUtil.getDescription(myField, true),
|
||||
RefactoringUIUtil.getDescription(ConflictsUtil.getContainer(element), true));
|
||||
conflicts.add(message);
|
||||
conflicts.put(element, message);
|
||||
}
|
||||
|
||||
for (PsiMember member : referencedWithVisibility) {
|
||||
if (!resolveHelper.isAccessible(member, element, null)) {
|
||||
String message = RefactoringBundle.message("0.will.not.be.accessible.from.1.after.inlining", RefactoringUIUtil.getDescription(member, true),
|
||||
RefactoringUIUtil.getDescription(ConflictsUtil.getContainer(element), true));
|
||||
conflicts.add(message);
|
||||
conflicts.put(member, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
|
||||
|
||||
protected boolean preprocessUsages(Ref<UsageInfo[]> refUsages) {
|
||||
UsageInfo[] usagesIn = refUsages.get();
|
||||
ArrayList<String> conflicts = new ArrayList<String>();
|
||||
Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
|
||||
|
||||
if (!myInlineThisOnly) {
|
||||
final PsiMethod[] superMethods = myMethod.findSuperMethods();
|
||||
@@ -113,7 +113,7 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
|
||||
final String message = method.hasModifierProperty(PsiModifier.ABSTRACT) ? RefactoringBundle
|
||||
.message("inlined.method.implements.method.from.0", method.getContainingClass().getQualifiedName()) : RefactoringBundle
|
||||
.message("inlined.method.overrides.method.from.0", method.getContainingClass().getQualifiedName());
|
||||
conflicts.add(message);
|
||||
conflicts.put(method, message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,6 +123,7 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
|
||||
ConflictsDialog dialog = new ConflictsDialog(myProject, conflicts);
|
||||
dialog.show();
|
||||
if (!dialog.isOK()) {
|
||||
if (dialog.isShowConflicts()) prepareSuccessful();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -138,7 +139,7 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
|
||||
public static void addInaccessibleMemberConflicts(final PsiElement element,
|
||||
final UsageInfo[] usages,
|
||||
final ReferencedElementsCollector collector,
|
||||
final ArrayList<String> conflicts) {
|
||||
final Map<PsiElement, String> conflicts) {
|
||||
element.accept(collector);
|
||||
final Map<PsiMember, Set<PsiMember>> containersToReferenced = getInaccessible(collector.myReferencedMembers, usages);
|
||||
|
||||
@@ -150,7 +151,7 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
|
||||
final String containerDescription = RefactoringUIUtil.getDescription(container, true);
|
||||
String message = RefactoringBundle.message("0.that.is.used.in.inlined.method.is.not.accessible.from.call.site.s.in.1",
|
||||
referencedDescription, containerDescription);
|
||||
conflicts.add(CommonRefactoringUtil.capitalize(message));
|
||||
conflicts.put(container, CommonRefactoringUtil.capitalize(message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -124,15 +124,15 @@ public class InlineToAnonymousClassProcessor extends BaseRefactoringProcessor {
|
||||
CommonRefactoringUtil.showErrorMessage(RefactoringBundle.message("inline.to.anonymous.refactoring"), s, null, myClass.getProject());
|
||||
return false;
|
||||
}
|
||||
ArrayList<String> conflicts = getConflicts(usages);
|
||||
Map<PsiElement, String> conflicts = getConflicts(usages);
|
||||
if (!conflicts.isEmpty()) {
|
||||
return showConflicts(conflicts);
|
||||
}
|
||||
return super.preprocessUsages(refUsages);
|
||||
}
|
||||
|
||||
public ArrayList<String> getConflicts(final UsageInfo[] usages) {
|
||||
ArrayList<String> result = new ArrayList<String>();
|
||||
public Map<PsiElement, String> getConflicts(final UsageInfo[] usages) {
|
||||
Map<PsiElement, String> result = new LinkedHashMap<PsiElement, String>();
|
||||
ReferencedElementsCollector collector = new ReferencedElementsCollector() {
|
||||
protected void checkAddMember(@NotNull final PsiMember member) {
|
||||
if (PsiTreeUtil.isAncestor(myClass, member, false)) {
|
||||
|
||||
+4
-5
@@ -29,7 +29,6 @@ import com.intellij.util.Processor;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -131,7 +130,7 @@ public class InlineSuperClassRefactoringProcessor extends FixableUsagesRefactori
|
||||
|
||||
@Override
|
||||
protected boolean preprocessUsages(final Ref<UsageInfo[]> refUsages) {
|
||||
final List<String> conflicts = new ArrayList<String>();
|
||||
final Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
|
||||
final PushDownConflicts pushDownConflicts = new PushDownConflicts(mySuperClass, myMemberInfos);
|
||||
for (PsiClass targetClass : myTargetClasses) {
|
||||
for (MemberInfo info : myMemberInfos) {
|
||||
@@ -140,14 +139,14 @@ public class InlineSuperClassRefactoringProcessor extends FixableUsagesRefactori
|
||||
}
|
||||
}
|
||||
checkConflicts(refUsages, conflicts);
|
||||
conflicts.addAll(pushDownConflicts.getConflicts());
|
||||
conflicts.putAll(pushDownConflicts.getConflicts());
|
||||
return showConflicts(conflicts);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean showConflicts(final List<String> conflicts) {
|
||||
protected boolean showConflicts(final Map<PsiElement, String> conflicts) {
|
||||
if (!conflicts.isEmpty() && ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
throw new RuntimeException(StringUtil.join(conflicts, "\n"));
|
||||
throw new RuntimeException(StringUtil.join(conflicts.values(), "\n"));
|
||||
}
|
||||
return super.showConflicts(conflicts);
|
||||
}
|
||||
|
||||
+3
-2
@@ -1,10 +1,11 @@
|
||||
package com.intellij.refactoring.introduceParameter;
|
||||
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Maxim.Medvedev
|
||||
@@ -16,7 +17,7 @@ public interface IntroduceParameterMethodUsagesProcessor {
|
||||
|
||||
boolean isMethodUsage(UsageInfo usage);
|
||||
|
||||
List<String> findConflicts(IntroduceParameterData data, UsageInfo[] usages);
|
||||
Map<PsiElement, String> findConflicts(IntroduceParameterData data, UsageInfo[] usages);
|
||||
|
||||
boolean processChangeMethodUsage(IntroduceParameterData data, UsageInfo usage, UsageInfo[] usages) throws IncorrectOperationException;
|
||||
|
||||
|
||||
+14
-10
@@ -11,6 +11,7 @@ package com.intellij.refactoring.introduceParameter;
|
||||
import com.intellij.codeInsight.ChangeContextUtil;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
@@ -38,6 +39,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class IntroduceParameterProcessor extends BaseRefactoringProcessor implements IntroduceParameterData {
|
||||
@@ -190,12 +193,13 @@ public class IntroduceParameterProcessor extends BaseRefactoringProcessor implem
|
||||
|
||||
protected boolean preprocessUsages(Ref<UsageInfo[]> refUsages) {
|
||||
UsageInfo[] usagesIn = refUsages.get();
|
||||
ArrayList<String> conflicts = new ArrayList<String> ();
|
||||
Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
|
||||
|
||||
AnySameNameVariables anySameNameVariables = new AnySameNameVariables();
|
||||
myMethodToReplaceIn.accept(anySameNameVariables);
|
||||
if (anySameNameVariables.getConflict() != null) {
|
||||
conflicts.add(anySameNameVariables.getConflict());
|
||||
final Pair<PsiElement, String> conflictPair = anySameNameVariables.getConflict();
|
||||
if (conflictPair != null) {
|
||||
conflicts.put(conflictPair.first, conflictPair.second);
|
||||
}
|
||||
|
||||
if (!myGenerateDelegate) {
|
||||
@@ -209,7 +213,7 @@ public class IntroduceParameterProcessor extends BaseRefactoringProcessor implem
|
||||
for (UsageInfo usageInfo : usagesIn) {
|
||||
if (!(usageInfo.getElement() instanceof PsiMethod) && !(usageInfo instanceof InternalUsageInfo)) {
|
||||
if (!PsiTreeUtil.isAncestor(myMethodToReplaceIn.getContainingClass(), usageInfo.getElement(), false)) {
|
||||
conflicts.add(RefactoringBundle.message("parameter.initializer.contains.0.but.not.all.calls.to.method.are.in.its.class",
|
||||
conflicts.put(myParameterInitializer, RefactoringBundle.message("parameter.initializer.contains.0.but.not.all.calls.to.method.are.in.its.class",
|
||||
CommonRefactoringUtil.htmlEmphasize(PsiKeyword.SUPER)));
|
||||
break;
|
||||
}
|
||||
@@ -219,13 +223,13 @@ public class IntroduceParameterProcessor extends BaseRefactoringProcessor implem
|
||||
}
|
||||
|
||||
for (IntroduceParameterMethodUsagesProcessor processor : IntroduceParameterMethodUsagesProcessor.EP_NAME.getExtensions()) {
|
||||
conflicts.addAll(processor.findConflicts(this, refUsages.get()));
|
||||
conflicts.putAll(processor.findConflicts(this, refUsages.get()));
|
||||
}
|
||||
|
||||
return showConflicts(conflicts);
|
||||
}
|
||||
|
||||
private void detectAccessibilityConflicts(final UsageInfo[] usageArray, ArrayList<String> conflicts) {
|
||||
private void detectAccessibilityConflicts(final UsageInfo[] usageArray, Map<PsiElement, String> conflicts) {
|
||||
if (myParameterInitializer != null) {
|
||||
final ReferencedElementsCollector collector = new ReferencedElementsCollector();
|
||||
myParameterInitializer.accept(collector);
|
||||
@@ -242,7 +246,7 @@ public class IntroduceParameterProcessor extends BaseRefactoringProcessor implem
|
||||
"0.is.not.accesible.from.1.value.for.introduced.parameter.in.that.method.call.will.be.incorrect",
|
||||
RefactoringUIUtil.getDescription(element, true),
|
||||
RefactoringUIUtil.getDescription(ConflictsUtil.getContainer(place), true));
|
||||
conflicts.add(message);
|
||||
conflicts.put(element, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -274,9 +278,9 @@ public class IntroduceParameterProcessor extends BaseRefactoringProcessor implem
|
||||
}
|
||||
|
||||
public class AnySameNameVariables extends JavaRecursiveElementWalkingVisitor {
|
||||
private String conflict = null;
|
||||
private Pair<PsiElement, String> conflict = null;
|
||||
|
||||
public String getConflict() {
|
||||
public Pair<PsiElement, String> getConflict() {
|
||||
return conflict;
|
||||
}
|
||||
|
||||
@@ -286,7 +290,7 @@ public class IntroduceParameterProcessor extends BaseRefactoringProcessor implem
|
||||
String descr = RefactoringBundle.message("there.is.already.a.0.it.will.conflict.with.an.introduced.parameter",
|
||||
RefactoringUIUtil.getDescription(variable, true));
|
||||
|
||||
conflict = CommonRefactoringUtil.capitalize(descr);
|
||||
conflict = Pair.<PsiElement, String>create(variable, CommonRefactoringUtil.capitalize(descr));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -12,17 +12,17 @@ import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.refactoring.util.FieldConflictsResolver;
|
||||
import com.intellij.refactoring.util.RefactoringUtil;
|
||||
import com.intellij.util.VisibilityUtil;
|
||||
import com.intellij.refactoring.util.usageInfo.DefaultConstructorImplicitUsageInfo;
|
||||
import com.intellij.refactoring.util.javadoc.MethodJavaDocHelper;
|
||||
import com.intellij.refactoring.util.usageInfo.DefaultConstructorImplicitUsageInfo;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.VisibilityUtil;
|
||||
import gnu.trove.TIntArrayList;
|
||||
import gnu.trove.TIntProcedure;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Maxim.Medvedev
|
||||
@@ -123,8 +123,8 @@ public class JavaIntroduceParameterMethodUsagesProcessor implements IntroducePar
|
||||
}
|
||||
|
||||
|
||||
public List<String> findConflicts(IntroduceParameterData data, UsageInfo[] usages) {
|
||||
return Collections.emptyList();
|
||||
public Map<PsiElement, String> findConflicts(IntroduceParameterData data, UsageInfo[] usages) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
public boolean processChangeMethodSignature(IntroduceParameterData data, UsageInfo usage, UsageInfo[] usages) throws IncorrectOperationException {
|
||||
|
||||
@@ -11,7 +11,8 @@ import com.intellij.refactoring.util.RefactoringUIUtil;
|
||||
import com.intellij.refactoring.util.occurences.ExpressionOccurenceManager;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class InputValidator implements IntroduceVariableBase.Validator {
|
||||
private final Project myProject;
|
||||
@@ -31,7 +32,7 @@ public class InputValidator implements IntroduceVariableBase.Validator {
|
||||
}
|
||||
final PsiElement scope = anchor.getParent();
|
||||
if(scope == null) return true;
|
||||
final ArrayList<String> conflicts = new ArrayList<String>();
|
||||
final Map<PsiElement, String> conflicts = new LinkedHashMap<PsiElement, String>();
|
||||
final HashSet<PsiVariable> reportedVariables = new HashSet<PsiVariable>();
|
||||
JavaUnresolvableLocalCollisionDetector.CollidingVariableVisitor visitor = new JavaUnresolvableLocalCollisionDetector.CollidingVariableVisitor() {
|
||||
public void visitCollidingElement(PsiVariable collidingVariable) {
|
||||
@@ -39,7 +40,7 @@ public class InputValidator implements IntroduceVariableBase.Validator {
|
||||
if (!reportedVariables.contains(collidingVariable)) {
|
||||
reportedVariables.add(collidingVariable);
|
||||
String message = RefactoringBundle.message("introduced.variable.will.conflict.with.0", RefactoringUIUtil.getDescription(collidingVariable, true));
|
||||
conflicts.add(message);
|
||||
conflicts.put(collidingVariable, message);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -54,7 +55,7 @@ public class InputValidator implements IntroduceVariableBase.Validator {
|
||||
}
|
||||
|
||||
if (conflicts.size() > 0) {
|
||||
return myIntroduceVariableBase.reportConflicts(conflicts, myProject);
|
||||
return myIntroduceVariableBase.reportConflicts(conflicts, myProject, settings);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
+5
-4
@@ -49,6 +49,7 @@ import javax.swing.event.ListSelectionListener;
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class IntroduceVariableBase extends IntroduceHandlerBase implements RefactoringActionHandler {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.introduceVariable.IntroduceVariableBase");
|
||||
@@ -681,10 +682,10 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase impleme
|
||||
boolean isOK(IntroduceVariableSettings dialog);
|
||||
}
|
||||
|
||||
protected abstract boolean reportConflicts(ArrayList<String> conflicts, final Project project);
|
||||
protected abstract boolean reportConflicts(Map<PsiElement, String> conflicts, final Project project, IntroduceVariableSettings dialog);
|
||||
|
||||
|
||||
public static void checkInLoopCondition(PsiExpression occurence, List<String> conflicts) {
|
||||
public static void checkInLoopCondition(PsiExpression occurence, Map<PsiElement, String> conflicts) {
|
||||
final PsiElement loopForLoopCondition = RefactoringUtil.getLoopForLoopCondition(occurence);
|
||||
if (loopForLoopCondition == null) return;
|
||||
final List<PsiVariable> referencedVariables = RefactoringUtil.collectReferencedVariables(occurence);
|
||||
@@ -698,9 +699,9 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase impleme
|
||||
if (!modifiedInBody.isEmpty()) {
|
||||
for (PsiVariable variable : modifiedInBody) {
|
||||
final String message = RefactoringBundle.message("is.modified.in.loop.body", RefactoringUIUtil.getDescription(variable, false));
|
||||
conflicts.add(CommonRefactoringUtil.capitalize(message));
|
||||
conflicts.put(variable, CommonRefactoringUtil.capitalize(message));
|
||||
}
|
||||
conflicts.add(RefactoringBundle.message("introducing.variable.may.break.code.logic"));
|
||||
conflicts.put(occurence, RefactoringBundle.message("introducing.variable.may.break.code.logic"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+8
-2
@@ -8,6 +8,7 @@ import com.intellij.openapi.editor.markup.RangeHighlighter;
|
||||
import com.intellij.openapi.editor.markup.TextAttributes;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.wm.WindowManager;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiExpression;
|
||||
import com.intellij.psi.PsiType;
|
||||
@@ -18,6 +19,7 @@ import com.intellij.refactoring.ui.TypeSelectorManagerImpl;
|
||||
import com.intellij.refactoring.util.CommonRefactoringUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
public class IntroduceVariableHandler extends IntroduceVariableBase {
|
||||
|
||||
@@ -70,9 +72,13 @@ public class IntroduceVariableHandler extends IntroduceVariableBase {
|
||||
WindowManager.getInstance().getStatusBar(project).setInfo(RefactoringBundle.message("press.escape.to.remove.the.highlighting"));
|
||||
}
|
||||
|
||||
protected boolean reportConflicts(final ArrayList<String> conflicts, final Project project) {
|
||||
protected boolean reportConflicts(final Map<PsiElement, String> conflicts, final Project project, IntroduceVariableSettings dialog) {
|
||||
ConflictsDialog conflictsDialog = new ConflictsDialog(project, conflicts);
|
||||
conflictsDialog.show();
|
||||
return conflictsDialog.isOK();
|
||||
final boolean ok = conflictsDialog.isOK();
|
||||
if (!ok && conflictsDialog.isShowConflicts()) {
|
||||
if (dialog instanceof DialogWrapper) ((DialogWrapper)dialog).close(DialogWrapper.CANCEL_EXIT_CODE);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
}
|
||||
|
||||
+8
-7
@@ -102,32 +102,33 @@ public class IntroduceParameterObjectProcessor extends FixableUsagesRefactoringP
|
||||
|
||||
@Override
|
||||
protected boolean preprocessUsages(final Ref<UsageInfo[]> refUsages) {
|
||||
ArrayList<String> conflicts = new ArrayList<String>();
|
||||
Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
|
||||
if (myUseExistingClass) {
|
||||
if (existingClass == null) {
|
||||
conflicts.add(RefactorJBundle.message("cannot.perform.the.refactoring") + "Could not find the selected class");
|
||||
conflicts.put(null, RefactorJBundle.message("cannot.perform.the.refactoring") + "Could not find the selected class");
|
||||
}
|
||||
final String incompatibilityMessage = "Selected class is not compatible with chosen parameters";
|
||||
if (!myExistingClassCompatible) {
|
||||
conflicts
|
||||
.add(RefactorJBundle.message("cannot.perform.the.refactoring") + incompatibilityMessage);
|
||||
.put(existingClass, RefactorJBundle.message("cannot.perform.the.refactoring") + incompatibilityMessage);
|
||||
|
||||
}
|
||||
if (!paramsNeedingSetters.isEmpty()) {
|
||||
conflicts.add(RefactorJBundle.message("cannot.perform.the.refactoring") + incompatibilityMessage);
|
||||
conflicts.put(existingClass, RefactorJBundle.message("cannot.perform.the.refactoring") + incompatibilityMessage);
|
||||
}
|
||||
}
|
||||
else if (existingClass != null) {
|
||||
conflicts.add(RefactorJBundle.message("cannot.perform.the.refactoring") +
|
||||
conflicts.put(existingClass,
|
||||
RefactorJBundle.message("cannot.perform.the.refactoring") +
|
||||
RefactorJBundle.message("there.already.exists.a.class.with.the.chosen.name"));
|
||||
}
|
||||
return showConflicts(conflicts);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean showConflicts(final List<String> conflicts) {
|
||||
protected boolean showConflicts(final Map<PsiElement, String> conflicts) {
|
||||
if (!conflicts.isEmpty() && ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
throw new RuntimeException(StringUtil.join(conflicts, "\n"));
|
||||
throw new RuntimeException(StringUtil.join(conflicts.values(), "\n"));
|
||||
}
|
||||
return super.showConflicts(conflicts);
|
||||
}
|
||||
|
||||
+5
-4
@@ -21,6 +21,7 @@ import org.jetbrains.annotations.NonNls;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author ven
|
||||
@@ -294,8 +295,8 @@ public class MakeClassStaticProcessor extends MakeMethodOrClassStaticProcessor<P
|
||||
}
|
||||
}
|
||||
|
||||
protected List<String> getConflictDescriptions(final UsageInfo[] usages) {
|
||||
final List<String> conflicts = super.getConflictDescriptions(usages);
|
||||
protected Map<PsiElement,String> getConflictDescriptions(final UsageInfo[] usages) {
|
||||
final Map<PsiElement, String> conflicts = super.getConflictDescriptions(usages);
|
||||
|
||||
//Check fields already exist
|
||||
if (mySettings.isMakeClassParameter()) {
|
||||
@@ -304,7 +305,7 @@ public class MakeClassStaticProcessor extends MakeMethodOrClassStaticProcessor<P
|
||||
if (existing != null) {
|
||||
String message = RefactoringBundle.message("there.is.already.a.0.in.1", RefactoringUIUtil.getDescription(existing, false),
|
||||
RefactoringUIUtil.getDescription(myMember, false));
|
||||
conflicts.add(message);
|
||||
conflicts.put(existing, message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -317,7 +318,7 @@ public class MakeClassStaticProcessor extends MakeMethodOrClassStaticProcessor<P
|
||||
if (existing != null) {
|
||||
String message = RefactoringBundle.message("there.is.already.a.0.in.1", RefactoringUIUtil.getDescription(existing, false),
|
||||
RefactoringUIUtil.getDescription(myMember, false));
|
||||
conflicts.add(message);
|
||||
conflicts.put(existing, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+20
-23
@@ -23,18 +23,15 @@ import com.intellij.refactoring.RefactoringBundle;
|
||||
import com.intellij.refactoring.ui.ConflictsDialog;
|
||||
import com.intellij.refactoring.util.CommonRefactoringUtil;
|
||||
import com.intellij.refactoring.util.ConflictsUtil;
|
||||
import com.intellij.refactoring.util.RefactoringUtil;
|
||||
import com.intellij.refactoring.util.RefactoringUIUtil;
|
||||
import com.intellij.refactoring.util.RefactoringUtil;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.usageView.UsageViewDescriptor;
|
||||
import com.intellij.usageView.UsageViewUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
public abstract class MakeMethodOrClassStaticProcessor<T extends PsiTypeParameterListOwner> extends BaseRefactoringProcessor {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.makeMethodStatic.MakeMethodStaticProcessor");
|
||||
@@ -57,11 +54,12 @@ public abstract class MakeMethodOrClassStaticProcessor<T extends PsiTypeParamete
|
||||
protected final boolean preprocessUsages(Ref<UsageInfo[]> refUsages) {
|
||||
UsageInfo[] usagesIn = refUsages.get();
|
||||
if (myPrepareSuccessfulSwingThreadCallback != null) {
|
||||
List<String> conflicts = getConflictDescriptions(usagesIn);
|
||||
Map<PsiElement, String> conflicts = getConflictDescriptions(usagesIn);
|
||||
if (conflicts.size() > 0) {
|
||||
ConflictsDialog conflictsDialog = new ConflictsDialog(myProject, conflicts);
|
||||
conflictsDialog.show();
|
||||
if (!conflictsDialog.isOK()) {
|
||||
if (conflictsDialog.isShowConflicts()) prepareSuccessful();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -95,8 +93,8 @@ public abstract class MakeMethodOrClassStaticProcessor<T extends PsiTypeParamete
|
||||
return result.toArray(new UsageInfo[result.size()]);
|
||||
}
|
||||
|
||||
protected List<String> getConflictDescriptions(UsageInfo[] usages) {
|
||||
ArrayList<String> conflicts = new ArrayList<String>();
|
||||
protected Map<PsiElement, String> getConflictDescriptions(UsageInfo[] usages) {
|
||||
Map<PsiElement, String> conflicts = new LinkedHashMap<PsiElement, String>();
|
||||
HashSet<PsiElement> processed = new HashSet<PsiElement>();
|
||||
String typeString = StringUtil.capitalize(UsageViewUtil.getType(myMember));
|
||||
for (UsageInfo usageInfo : usages) {
|
||||
@@ -117,12 +115,12 @@ public abstract class MakeMethodOrClassStaticProcessor<T extends PsiTypeParamete
|
||||
if (mySettings.getNameForField(field) == null) {
|
||||
String message = RefactoringBundle.message("0.uses.non.static.1.which.is.not.passed.as.a.parameter", typeString,
|
||||
RefactoringUIUtil.getDescription(field, true));
|
||||
conflicts.add(message);
|
||||
conflicts.put(field, message);
|
||||
}
|
||||
}
|
||||
else {
|
||||
String message = RefactoringBundle.message("0.uses.1.which.needs.class.instance", typeString, RefactoringUIUtil.getDescription(referencedElement, true));
|
||||
conflicts.add(message);
|
||||
conflicts.put(referencedElement, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -131,7 +129,7 @@ public abstract class MakeMethodOrClassStaticProcessor<T extends PsiTypeParamete
|
||||
final PsiMethod overridingMethod = ((PsiMethod)usageInfo.getElement());
|
||||
String message = RefactoringBundle.message("method.0.is.overridden.by.1", RefactoringUIUtil.getDescription(myMember, false),
|
||||
RefactoringUIUtil.getDescription(overridingMethod, true));
|
||||
conflicts.add(message);
|
||||
conflicts.put(overridingMethod, message);
|
||||
}
|
||||
else {
|
||||
PsiElement element = usageInfo.getElement();
|
||||
@@ -149,32 +147,31 @@ public abstract class MakeMethodOrClassStaticProcessor<T extends PsiTypeParamete
|
||||
|
||||
if (inaccessible.isEmpty()) continue;
|
||||
|
||||
conflicts.add(createInaccessibleFieldsConflictDescription(inaccessible, container));
|
||||
final Map<PsiElement, String> inaccessibleConflicts = createInaccessibleFieldsConflictDescription(inaccessible, container);
|
||||
conflicts.putAll(inaccessibleConflicts);
|
||||
}
|
||||
}
|
||||
return conflicts;
|
||||
}
|
||||
|
||||
private static String createInaccessibleFieldsConflictDescription(ArrayList<PsiField> inaccessible, PsiElement container) {
|
||||
private static Map<PsiElement, String> createInaccessibleFieldsConflictDescription(ArrayList<PsiField> inaccessible, PsiElement container) {
|
||||
if (inaccessible.size() == 1) {
|
||||
final PsiField field = inaccessible.get(0);
|
||||
return RefactoringBundle.message("field.0.is.not.accessible",
|
||||
return Collections.<PsiElement, String>singletonMap(field, RefactoringBundle.message("field.0.is.not.accessible",
|
||||
CommonRefactoringUtil.htmlEmphasize(field.getName()),
|
||||
RefactoringUIUtil.getDescription(container, true));
|
||||
RefactoringUIUtil.getDescription(container, true)));
|
||||
} else {
|
||||
StringBuffer fieldsBuffer = new StringBuffer();
|
||||
Map<PsiElement, String> result = new HashMap<PsiElement, String>();
|
||||
for (int j = 0; j < inaccessible.size(); j++) {
|
||||
PsiField field = inaccessible.get(j);
|
||||
result.put(field, RefactoringBundle.message("field.0.is.not.accessible",
|
||||
CommonRefactoringUtil.htmlEmphasize(field.getName()),
|
||||
RefactoringUIUtil.getDescription(container, true)));
|
||||
|
||||
|
||||
if (j > 0) {
|
||||
fieldsBuffer.append(", ");
|
||||
}
|
||||
fieldsBuffer.append(CommonRefactoringUtil.htmlEmphasize(field.getName()));
|
||||
}
|
||||
|
||||
return RefactoringBundle.message("fields.0.are.not.accessible",
|
||||
fieldsBuffer.toString(),
|
||||
RefactoringUIUtil.getDescription(container, true));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.ScrollType;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.refactoring.HelpID;
|
||||
import com.intellij.refactoring.RefactoringActionHandler;
|
||||
@@ -36,6 +37,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
public class JavaPullUpHandler implements RefactoringActionHandler, PullUpDialog.Callback, ElementsHandler {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.memberPullUp.JavaPullUpHandler");
|
||||
@@ -170,11 +172,13 @@ public class JavaPullUpHandler implements RefactoringActionHandler, PullUpDialog
|
||||
final MemberInfo[] infos = dialog.getSelectedMemberInfos();
|
||||
PsiClass superClass = dialog.getSuperClass();
|
||||
if (!checkWritable(superClass, infos)) return false;
|
||||
String[] conflicts = PullUpConflictsUtil.checkConflicts(infos, mySubclass, superClass, null, null, dialog.getContainmentVerifier());
|
||||
if (conflicts.length > 0) {
|
||||
LinkedHashMap<PsiElement,String> conflicts = PullUpConflictsUtil.checkConflicts(infos, mySubclass, superClass, null, null, dialog.getContainmentVerifier());
|
||||
if (!conflicts.isEmpty()) {
|
||||
ConflictsDialog conflictsDialog = new ConflictsDialog(myProject, conflicts);
|
||||
conflictsDialog.show();
|
||||
return conflictsDialog.isOK();
|
||||
final boolean ok = conflictsDialog.isOK();
|
||||
if (!ok && conflictsDialog.isShowConflicts()) dialog.close(DialogWrapper.CANCEL_EXIT_CODE);
|
||||
return ok;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -14,19 +14,21 @@ import com.intellij.psi.util.MethodSignatureUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import com.intellij.refactoring.RefactoringBundle;
|
||||
import com.intellij.refactoring.util.*;
|
||||
import com.intellij.refactoring.util.CommonRefactoringUtil;
|
||||
import com.intellij.refactoring.util.RefactoringHierarchyUtil;
|
||||
import com.intellij.refactoring.util.RefactoringUIUtil;
|
||||
import com.intellij.refactoring.util.RefactoringUtil;
|
||||
import com.intellij.refactoring.util.classMembers.ClassMemberReferencesVisitor;
|
||||
import com.intellij.refactoring.util.classMembers.InterfaceContainmentVerifier;
|
||||
import com.intellij.refactoring.util.classMembers.MemberInfo;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class PullUpConflictsUtil {
|
||||
private PullUpConflictsUtil() {}
|
||||
|
||||
public static String[] checkConflicts(final MemberInfo[] infos,
|
||||
public static LinkedHashMap<PsiElement, String> checkConflicts(final MemberInfo[] infos,
|
||||
PsiClass subclass,
|
||||
PsiClass superClass,
|
||||
PsiPackage targetPackage,
|
||||
@@ -58,11 +60,11 @@ public class PullUpConflictsUtil {
|
||||
movedMembers.add(member);
|
||||
}
|
||||
}
|
||||
final LinkedHashSet<String> conflictsList = new LinkedHashSet<String>();
|
||||
final LinkedHashMap<PsiElement, String> conflicts = new LinkedHashMap<PsiElement, String>();
|
||||
if (superClass != null) {
|
||||
checkSuperclassMembers(superClass, infos, conflictsList);
|
||||
checkSuperclassMembers(superClass, infos, conflicts);
|
||||
if (isInterfaceTarget) {
|
||||
checkInterfaceTarget(infos, conflictsList);
|
||||
checkInterfaceTarget(infos, conflicts);
|
||||
}
|
||||
}
|
||||
// check if moved methods use other members in the classes between Subclass and Superclass
|
||||
@@ -71,7 +73,7 @@ public class PullUpConflictsUtil {
|
||||
if (member instanceof PsiMethod || member instanceof PsiClass) {
|
||||
ConflictingUsagesOfSubClassMembers visitor =
|
||||
new ConflictingUsagesOfSubClassMembers(member, movedMembers, abstractMethods, subclass, superClass,
|
||||
superClass != null ? null : targetPackage, conflictsList,
|
||||
superClass != null ? null : targetPackage, conflicts,
|
||||
interfaceContainmentVerifier);
|
||||
member.accept(visitor);
|
||||
}
|
||||
@@ -83,11 +85,11 @@ public class PullUpConflictsUtil {
|
||||
checkModuleConflictsList.add(method.getTypeParameterList());
|
||||
}
|
||||
RefactoringUtil.analyzeModuleConflicts(subclass.getProject(), checkModuleConflictsList,
|
||||
new UsageInfo[0], targetRepresentativeElement, conflictsList);
|
||||
return ArrayUtil.toStringArray(conflictsList);
|
||||
new UsageInfo[0], targetRepresentativeElement, conflicts);
|
||||
return conflicts;
|
||||
}
|
||||
|
||||
private static void checkInterfaceTarget(MemberInfo[] infos, LinkedHashSet<String> conflictsList) {
|
||||
private static void checkInterfaceTarget(MemberInfo[] infos, LinkedHashMap<PsiElement, String> conflictsList) {
|
||||
for (MemberInfo info : infos) {
|
||||
PsiElement member = info.getMember();
|
||||
|
||||
@@ -98,21 +100,21 @@ public class PullUpConflictsUtil {
|
||||
String message =
|
||||
RefactoringBundle.message("0.is.not.static.it.cannot.be.moved.to.the.interface", RefactoringUIUtil.getDescription(member, false));
|
||||
message = CommonRefactoringUtil.capitalize(message);
|
||||
conflictsList.add(message);
|
||||
conflictsList.put(member, message);
|
||||
}
|
||||
}
|
||||
|
||||
if (member instanceof PsiField && ((PsiField)member).getInitializer() == null) {
|
||||
String message = RefactoringBundle.message("0.is.not.initialized.in.declaration.such.fields.are.not.allowed.in.interfaces",
|
||||
RefactoringUIUtil.getDescription(member, false));
|
||||
conflictsList.add(CommonRefactoringUtil.capitalize(message));
|
||||
conflictsList.put(member, CommonRefactoringUtil.capitalize(message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkSuperclassMembers(PsiClass superClass,
|
||||
MemberInfo[] infos,
|
||||
LinkedHashSet<String> conflictsList) {
|
||||
LinkedHashMap<PsiElement, String> conflictsList) {
|
||||
for (MemberInfo info : infos) {
|
||||
PsiMember member = info.getMember();
|
||||
boolean isConflict = false;
|
||||
@@ -133,7 +135,7 @@ public class PullUpConflictsUtil {
|
||||
RefactoringUIUtil.getDescription(superClass, false),
|
||||
RefactoringUIUtil.getDescription(member, false));
|
||||
message = CommonRefactoringUtil.capitalize(message);
|
||||
conflictsList.add(message);
|
||||
conflictsList.put(superClass, message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,13 +148,13 @@ public class PullUpConflictsUtil {
|
||||
private final PsiClass mySubclass;
|
||||
private final PsiClass mySuperClass;
|
||||
private final PsiPackage myTargetPackage;
|
||||
private final Set<String> myConflictsList;
|
||||
private final LinkedHashMap<PsiElement, String> myConflictsList;
|
||||
private final InterfaceContainmentVerifier myInterfaceContainmentVerifier;
|
||||
|
||||
ConflictingUsagesOfSubClassMembers(PsiElement scope,
|
||||
Set<PsiElement> movedMembers, Set<PsiMethod> abstractMethods,
|
||||
PsiClass subclass, PsiClass superClass,
|
||||
PsiPackage targetPackage, Set<String> conflictsList,
|
||||
PsiPackage targetPackage, LinkedHashMap<PsiElement, String> conflictsList,
|
||||
InterfaceContainmentVerifier interfaceContainmentVerifier) {
|
||||
super(subclass);
|
||||
myScope = scope;
|
||||
@@ -186,7 +188,7 @@ public class PullUpConflictsUtil {
|
||||
RefactoringUIUtil.getDescription(myScope, false),
|
||||
RefactoringUIUtil.getDescription(classMember, true));
|
||||
message = CommonRefactoringUtil.capitalize(message);
|
||||
myConflictsList.add(message);
|
||||
myConflictsList.put(classMember, message);
|
||||
|
||||
}
|
||||
return;
|
||||
@@ -197,7 +199,7 @@ public class PullUpConflictsUtil {
|
||||
RefactoringUIUtil.getDescription(myScope, false),
|
||||
RefactoringUIUtil.getDescription(classMember, true));
|
||||
message = CommonRefactoringUtil.capitalize(message);
|
||||
myConflictsList.add(message);
|
||||
myConflictsList.put(classMember, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,15 +9,13 @@ import com.intellij.refactoring.util.RefactoringUIUtil;
|
||||
import com.intellij.refactoring.util.classMembers.ClassMemberReferencesVisitor;
|
||||
import com.intellij.refactoring.util.classMembers.MemberInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
public class PushDownConflicts {
|
||||
private final PsiClass myClass;
|
||||
private final Set<PsiMember> myMovedMembers;
|
||||
private final Set<PsiMember> myAbstractMembers;
|
||||
private final ArrayList<String> myConflicts;
|
||||
private final Map<PsiElement, String> myConflicts;
|
||||
|
||||
|
||||
public PushDownConflicts(PsiClass aClass, MemberInfo[] memberInfos) {
|
||||
@@ -35,14 +33,14 @@ public class PushDownConflicts {
|
||||
}
|
||||
}
|
||||
|
||||
myConflicts = new ArrayList<String>();
|
||||
myConflicts = new HashMap<PsiElement, String>();
|
||||
}
|
||||
|
||||
public boolean isAnyConflicts() {
|
||||
return !myConflicts.isEmpty();
|
||||
}
|
||||
|
||||
public ArrayList<String> getConflicts() {
|
||||
public Map<PsiElement, String> getConflicts() {
|
||||
return myConflicts;
|
||||
}
|
||||
|
||||
@@ -71,7 +69,7 @@ public class PushDownConflicts {
|
||||
if (qualifierType instanceof PsiClassType) {
|
||||
final PsiClass aClass = ((PsiClassType)qualifierType).resolve();
|
||||
if (!InheritanceUtil.isInheritorOrSelf(aClass, targetClass, true)) {
|
||||
myConflicts.add(RefactoringBundle.message("pushed.members.will.not.be.visible.from.certain.call.sites"));
|
||||
myConflicts.put(aClass, RefactoringBundle.message("pushed.members.will.not.be.visible.from.certain.call.sites"));
|
||||
break Members;
|
||||
}
|
||||
}
|
||||
@@ -84,9 +82,10 @@ public class PushDownConflicts {
|
||||
public void checkMemberPlacementInTargetClassConflict(final PsiClass targetClass, final PsiMember movedMember) {
|
||||
if (movedMember instanceof PsiField) {
|
||||
String name = movedMember.getName();
|
||||
if (targetClass.findFieldByName(name, false) != null) {
|
||||
final PsiField field = targetClass.findFieldByName(name, false);
|
||||
if (field != null) {
|
||||
String message = RefactoringBundle.message("0.already.contains.field.1", RefactoringUIUtil.getDescription(targetClass, false), CommonRefactoringUtil.htmlEmphasize(name));
|
||||
myConflicts.add(CommonRefactoringUtil.capitalize(message));
|
||||
myConflicts.put(field, CommonRefactoringUtil.capitalize(message));
|
||||
}
|
||||
}
|
||||
else if (movedMember instanceof PsiMethod) {
|
||||
@@ -94,10 +93,11 @@ public class PushDownConflicts {
|
||||
assert modifierList != null;
|
||||
if (!modifierList.hasModifierProperty(PsiModifier.ABSTRACT)) {
|
||||
PsiMethod method = (PsiMethod)movedMember;
|
||||
if (targetClass.findMethodBySignature(method, false) != null) {
|
||||
final PsiMethod overrider = targetClass.findMethodBySignature(method, false);
|
||||
if (overrider != null) {
|
||||
String message = RefactoringBundle.message("0.is.already.overridden.in.1",
|
||||
RefactoringUIUtil.getDescription(method, true), RefactoringUIUtil.getDescription(targetClass, false));
|
||||
myConflicts.add(CommonRefactoringUtil.capitalize(message));
|
||||
myConflicts.put(overrider, CommonRefactoringUtil.capitalize(message));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -111,7 +111,7 @@ public class PushDownConflicts {
|
||||
if (name.equals(innerClass.getName())) {
|
||||
String message = RefactoringBundle.message("0.already.contains.inner.class.named.1", RefactoringUIUtil.getDescription(targetClass, false),
|
||||
CommonRefactoringUtil.htmlEmphasize(name));
|
||||
myConflicts.add(message);
|
||||
myConflicts.put(innerClass, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -130,7 +130,7 @@ public class PushDownConflicts {
|
||||
String message = RefactoringBundle.message("0.uses.1.which.is.pushed.down", RefactoringUIUtil.getDescription(mySource, false),
|
||||
RefactoringUIUtil.getDescription(classMember, false));
|
||||
message = CommonRefactoringUtil.capitalize(message);
|
||||
myConflicts.add(message);
|
||||
myConflicts.put(mySource, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -12,8 +12,8 @@ import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author dsl
|
||||
@@ -60,7 +60,7 @@ public class AutocreatingSingleSourceRootMoveDestination extends AutocreatingMov
|
||||
}
|
||||
|
||||
public void analyzeModuleConflicts(final Collection<PsiElement> elements,
|
||||
ArrayList<String> conflicts, final UsageInfo[] usages) {
|
||||
Map<PsiElement,String> conflicts, final UsageInfo[] usages) {
|
||||
RefactoringUtil.analyzeModuleConflicts(getTargetPackage().getManager().getProject(), elements, usages, mySourceRoot, conflicts);
|
||||
}
|
||||
|
||||
|
||||
+8
-7
@@ -264,11 +264,12 @@ public class MoveClassToInnerProcessor extends BaseRefactoringProcessor {
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<String> getConflicts(final UsageInfo[] usages) {
|
||||
List<String> conflicts = new ArrayList<String>();
|
||||
public Map<PsiElement, String> getConflicts(final UsageInfo[] usages) {
|
||||
Map<PsiElement, String> conflicts = new LinkedHashMap<PsiElement, String>();
|
||||
|
||||
if (myTargetClass.findInnerClassByName(myClassToMove.getName(), false) != null) {
|
||||
conflicts.add(RefactoringBundle.message("move.to.inner.duplicate.inner.class",
|
||||
final PsiClass innerClass = myTargetClass.findInnerClassByName(myClassToMove.getName(), false);
|
||||
if (innerClass != null) {
|
||||
conflicts.put(innerClass, RefactoringBundle.message("move.to.inner.duplicate.inner.class",
|
||||
CommonRefactoringUtil.htmlEmphasize(myTargetClass.getQualifiedName()),
|
||||
CommonRefactoringUtil.htmlEmphasize(myClassToMove.getName())));
|
||||
}
|
||||
@@ -343,10 +344,10 @@ public class MoveClassToInnerProcessor extends BaseRefactoringProcessor {
|
||||
}
|
||||
|
||||
private class ConflictsCollector {
|
||||
private final List<String> myConflicts;
|
||||
private final Map<PsiElement, String> myConflicts;
|
||||
private final Set<PsiElement> myReportedContainers = new HashSet<PsiElement>();
|
||||
|
||||
public ConflictsCollector(final List<String> conflicts) {
|
||||
public ConflictsCollector(final Map<PsiElement, String> conflicts) {
|
||||
myConflicts = conflicts;
|
||||
}
|
||||
|
||||
@@ -361,7 +362,7 @@ public class MoveClassToInnerProcessor extends BaseRefactoringProcessor {
|
||||
final String message = RefactoringBundle.message("element.will.no.longer.be.accessible",
|
||||
targetDescription,
|
||||
RefactoringUIUtil.getDescription(container, true));
|
||||
myConflicts.add(message);
|
||||
myConflicts.put(targetElement, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
-12
@@ -120,7 +120,7 @@ public class MoveClassesOrPackagesProcessor extends BaseRefactoringProcessor {
|
||||
@NotNull
|
||||
protected UsageInfo[] findUsages() {
|
||||
List<UsageInfo> allUsages = new ArrayList<UsageInfo>();
|
||||
ArrayList<String> conflicts = new ArrayList<String>();
|
||||
Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
|
||||
for (PsiElement element : myElementsToMove) {
|
||||
String newName = getNewQName(element);
|
||||
final UsageInfo[] usages = MoveClassesOrPackagesUtil.findUsages(element, mySearchInComments,
|
||||
@@ -148,14 +148,14 @@ public class MoveClassesOrPackagesProcessor extends BaseRefactoringProcessor {
|
||||
}
|
||||
|
||||
protected static class ConflictsUsageInfo extends UsageInfo {
|
||||
private final ArrayList<String> myConflicts;
|
||||
private final Map<PsiElement, String> myConflicts;
|
||||
|
||||
public ConflictsUsageInfo(PsiElement pseudoElement, ArrayList<String> conflicts) {
|
||||
public ConflictsUsageInfo(PsiElement pseudoElement, Map<PsiElement, String> conflicts) {
|
||||
super(pseudoElement);
|
||||
myConflicts = conflicts;
|
||||
}
|
||||
|
||||
public ArrayList<String> getConflicts() {
|
||||
public Map<PsiElement, String> getConflicts() {
|
||||
return myConflicts;
|
||||
}
|
||||
}
|
||||
@@ -164,11 +164,11 @@ public class MoveClassesOrPackagesProcessor extends BaseRefactoringProcessor {
|
||||
|
||||
protected boolean preprocessUsages(Ref<UsageInfo[]> refUsages) {
|
||||
final UsageInfo[] usages = refUsages.get();
|
||||
final ArrayList<String> conflicts = new ArrayList<String>();
|
||||
final Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
|
||||
ArrayList<UsageInfo> filteredUsages = new ArrayList<UsageInfo>();
|
||||
for (UsageInfo usage : usages) {
|
||||
if (usage instanceof ConflictsUsageInfo) {
|
||||
conflicts.addAll(((ConflictsUsageInfo)usage).getConflicts());
|
||||
conflicts.putAll(((ConflictsUsageInfo)usage).getConflicts());
|
||||
}
|
||||
else {
|
||||
filteredUsages.add(usage);
|
||||
@@ -188,7 +188,7 @@ public class MoveClassesOrPackagesProcessor extends BaseRefactoringProcessor {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void detectPackageLocalsUsed(final ArrayList<String> conflicts) {
|
||||
private void detectPackageLocalsUsed(final Map<PsiElement, String> conflicts) {
|
||||
PackageLocalsUsageCollector visitor = new PackageLocalsUsageCollector(myElementsToMove, myTargetPackage, conflicts);
|
||||
|
||||
for (PsiElement element : myElementsToMove) {
|
||||
@@ -199,7 +199,7 @@ public class MoveClassesOrPackagesProcessor extends BaseRefactoringProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
private void detectPackageLocalsMoved(final UsageInfo[] usages, final ArrayList<String> conflicts) {
|
||||
private void detectPackageLocalsMoved(final UsageInfo[] usages, final Map<PsiElement, String> conflicts) {
|
||||
// final HashSet reportedPackageLocalUsed = new HashSet();
|
||||
final HashSet<PsiClass> movedClasses = new HashSet<PsiClass>();
|
||||
final HashMap<PsiClass,HashSet<PsiElement>> reportedClassToContainers = new HashMap<PsiClass, HashSet<PsiElement>>();
|
||||
@@ -237,7 +237,7 @@ public class MoveClassesOrPackagesProcessor extends BaseRefactoringProcessor {
|
||||
CommonRefactoringUtil.htmlEmphasize(aClass.getName()),
|
||||
RefactoringUIUtil.getDescription(
|
||||
container, true));
|
||||
conflicts.add(message);
|
||||
conflicts.put(aClass, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -470,11 +470,11 @@ public class MoveClassesOrPackagesProcessor extends BaseRefactoringProcessor {
|
||||
}
|
||||
|
||||
private class MyClassInstanceReferenceVisitor implements ClassInstanceScanner.ClassInstanceReferenceVisitor {
|
||||
private final ArrayList<String> myConflicts;
|
||||
private final Map<PsiElement, String> myConflicts;
|
||||
private final HashMap<PsiModifierListOwner,HashSet<PsiElement>> myReportedElementToContainer = new HashMap<PsiModifierListOwner, HashSet<PsiElement>>();
|
||||
private final HashMap<PsiClass, RefactoringUtil.IsDescendantOf> myIsDescendantOfCache = new HashMap<PsiClass,RefactoringUtil.IsDescendantOf>();
|
||||
|
||||
public MyClassInstanceReferenceVisitor(ArrayList<String> conflicts) {
|
||||
public MyClassInstanceReferenceVisitor(Map<PsiElement, String> conflicts) {
|
||||
myConflicts = conflicts;
|
||||
}
|
||||
|
||||
@@ -538,7 +538,7 @@ public class MoveClassesOrPackagesProcessor extends BaseRefactoringProcessor {
|
||||
if (!myTargetPackage.equalToPackage(aPackage)) {
|
||||
String message = RefactoringBundle.message("0.will.be.inaccessible.from.1", RefactoringUIUtil.getDescription(member, true),
|
||||
RefactoringUIUtil.getDescription(container, true));
|
||||
myConflicts.add(CommonRefactoringUtil.capitalize(message));
|
||||
myConflicts.put(member, CommonRefactoringUtil.capitalize(message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -9,8 +9,8 @@ import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author dsl
|
||||
@@ -77,7 +77,7 @@ public class MultipleRootsMoveDestination extends AutocreatingMoveDestination {
|
||||
}
|
||||
|
||||
public void analyzeModuleConflicts(final Collection<PsiElement> elements,
|
||||
ArrayList<String> conflicts, final UsageInfo[] usages) {
|
||||
Map<PsiElement,String> conflicts, final UsageInfo[] usages) {
|
||||
}
|
||||
|
||||
public PsiDirectory getTargetIfExists(PsiDirectory source) {
|
||||
|
||||
+7
-7
@@ -4,22 +4,22 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.refactoring.PackageWrapper;
|
||||
import com.intellij.refactoring.RefactoringBundle;
|
||||
import com.intellij.refactoring.util.ConflictsUtil;
|
||||
import com.intellij.util.VisibilityUtil;
|
||||
import com.intellij.refactoring.util.RefactoringUIUtil;
|
||||
import com.intellij.refactoring.util.CommonRefactoringUtil;
|
||||
import com.intellij.refactoring.util.ConflictsUtil;
|
||||
import com.intellij.refactoring.util.RefactoringUIUtil;
|
||||
import com.intellij.util.VisibilityUtil;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
class PackageLocalsUsageCollector extends JavaRecursiveElementWalkingVisitor {
|
||||
private final HashMap<PsiElement,HashSet<PsiElement>> myReported = new HashMap<PsiElement, HashSet<PsiElement>>();
|
||||
private final PsiElement[] myElementsToMove;
|
||||
private final List<String> myConflicts;
|
||||
private final Map<PsiElement, String> myConflicts;
|
||||
private final PackageWrapper myTargetPackage;
|
||||
|
||||
public PackageLocalsUsageCollector(final PsiElement[] elementsToMove, final PackageWrapper targetPackage, List<String> conflicts) {
|
||||
public PackageLocalsUsageCollector(final PsiElement[] elementsToMove, final PackageWrapper targetPackage, Map<PsiElement,String> conflicts) {
|
||||
myElementsToMove = elementsToMove;
|
||||
myConflicts = conflicts;
|
||||
myTargetPackage = targetPackage;
|
||||
@@ -56,7 +56,7 @@ class PackageLocalsUsageCollector extends JavaRecursiveElementWalkingVisitor {
|
||||
final String message = RefactoringBundle.message("0.uses.a.package.local.1",
|
||||
RefactoringUIUtil.getDescription(container, true),
|
||||
RefactoringUIUtil.getDescription(resolved, true));
|
||||
myConflicts.add(CommonRefactoringUtil.capitalize(message));
|
||||
myConflicts.put(resolved, CommonRefactoringUtil.capitalize(message));
|
||||
reportedRefs.add(container);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -7,8 +7,8 @@ import com.intellij.refactoring.PackageWrapper;
|
||||
import com.intellij.refactoring.util.RefactoringUtil;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author dsl
|
||||
@@ -54,7 +54,7 @@ public class SingleSourceRootMoveDestination implements MoveDestination {
|
||||
}
|
||||
|
||||
public void analyzeModuleConflicts(final Collection<PsiElement> elements,
|
||||
ArrayList<String> conflicts, final UsageInfo[] usages) {
|
||||
Map<PsiElement,String> conflicts, final UsageInfo[] usages) {
|
||||
RefactoringUtil.analyzeModuleConflicts(myPackage.getManager().getProject(), elements, usages, myTargetDirectory, conflicts);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,10 @@ import com.intellij.refactoring.listeners.RefactoringElementListener;
|
||||
import com.intellij.refactoring.move.MoveCallback;
|
||||
import com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesUtil;
|
||||
import com.intellij.refactoring.rename.RenameUtil;
|
||||
import com.intellij.refactoring.util.*;
|
||||
import com.intellij.refactoring.util.ConflictsUtil;
|
||||
import com.intellij.refactoring.util.NonCodeUsageInfo;
|
||||
import com.intellij.refactoring.util.RefactoringUIUtil;
|
||||
import com.intellij.refactoring.util.RefactoringUtil;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.usageView.UsageViewDescriptor;
|
||||
import com.intellij.usageView.UsageViewUtil;
|
||||
@@ -38,10 +41,7 @@ import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
public class MoveInnerProcessor extends BaseRefactoringProcessor {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.move.moveInner.MoveInnerProcessor");
|
||||
@@ -326,7 +326,7 @@ public class MoveInnerProcessor extends BaseRefactoringProcessor {
|
||||
}
|
||||
|
||||
protected boolean preprocessUsages(Ref<UsageInfo[]> refUsages) {
|
||||
final ArrayList<String> conflicts = new ArrayList<String>();
|
||||
final Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
|
||||
|
||||
class Visitor extends JavaRecursiveElementWalkingVisitor {
|
||||
private final HashMap<PsiElement,HashSet<PsiElement>> reported = new HashMap<PsiElement, HashSet<PsiElement>>();
|
||||
@@ -347,7 +347,7 @@ public class MoveInnerProcessor extends BaseRefactoringProcessor {
|
||||
String message = RefactoringBundle.message("0.will.become.inaccessible.from.1",
|
||||
RefactoringUIUtil.getDescription(resolved, true),
|
||||
RefactoringUIUtil.getDescription(container, true));
|
||||
conflicts.add(message);
|
||||
conflicts.put(resolved, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -69,18 +69,18 @@ public class MoveInstanceMethodProcessor extends BaseRefactoringProcessor{
|
||||
|
||||
protected boolean preprocessUsages(Ref<UsageInfo[]> refUsages) {
|
||||
final UsageInfo[] usages = refUsages.get();
|
||||
ArrayList<String> conflicts = new ArrayList<String>();
|
||||
Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
|
||||
final Set<PsiMember> members = new HashSet<PsiMember>();
|
||||
members.add(myMethod);
|
||||
if (myTargetVariable instanceof PsiField) members.add((PsiMember)myTargetVariable);
|
||||
if (!myTargetClass.isInterface()) {
|
||||
conflicts.addAll(Arrays.asList(MoveMembersProcessor.analyzeAccessibilityConflicts(members, myTargetClass, new LinkedHashSet<String>(), myNewVisibility)));
|
||||
conflicts.putAll(MoveMembersProcessor.analyzeAccessibilityConflicts(members, myTargetClass, new LinkedHashMap<PsiElement, String>(), myNewVisibility));
|
||||
}
|
||||
else {
|
||||
for (final UsageInfo usage : usages) {
|
||||
if (usage instanceof InheritorUsageInfo) {
|
||||
conflicts.addAll(Arrays.asList(MoveMembersProcessor.analyzeAccessibilityConflicts(
|
||||
members, ((InheritorUsageInfo)usage).getInheritor(), new LinkedHashSet<String>(), myNewVisibility)));
|
||||
conflicts.putAll(MoveMembersProcessor.analyzeAccessibilityConflicts(
|
||||
members, ((InheritorUsageInfo)usage).getInheritor(), new LinkedHashMap<PsiElement, String>(), myNewVisibility));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -99,7 +99,7 @@ public class MoveInstanceMethodProcessor extends BaseRefactoringProcessor{
|
||||
String message = RefactoringBundle.message("0.contains.call.with.null.argument.for.parameter.1",
|
||||
RefactoringUIUtil.getDescription(ConflictsUtil.getContainer(methodCall), true),
|
||||
CommonRefactoringUtil.htmlEmphasize(parameter.getName()));
|
||||
conflicts.add(message);
|
||||
conflicts.put(instanceValue, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+17
-18
@@ -26,7 +26,6 @@ import com.intellij.refactoring.util.*;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.usageView.UsageViewDescriptor;
|
||||
import com.intellij.usageView.UsageViewUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.VisibilityUtil;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
@@ -223,7 +222,7 @@ public class MoveMembersProcessor extends BaseRefactoringProcessor {
|
||||
}
|
||||
|
||||
protected boolean preprocessUsages(Ref<UsageInfo[]> refUsages) {
|
||||
final ArrayList<String> conflicts = new ArrayList<String>();
|
||||
final Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
|
||||
final UsageInfo[] usages = refUsages.get();
|
||||
try {
|
||||
addInaccessiblleConflicts(conflicts, usages);
|
||||
@@ -235,7 +234,7 @@ public class MoveMembersProcessor extends BaseRefactoringProcessor {
|
||||
return showConflicts(conflicts);
|
||||
}
|
||||
|
||||
private void addInaccessiblleConflicts(final ArrayList<String> conflicts, final UsageInfo[] usages) throws IncorrectOperationException {
|
||||
private void addInaccessiblleConflicts(final Map<PsiElement, String> conflicts, final UsageInfo[] usages) throws IncorrectOperationException {
|
||||
String newVisibility = myNewVisibility;
|
||||
if (VisibilityUtil.ESCALATE_VISIBILITY.equals(newVisibility)) { //Still need to check for access object
|
||||
newVisibility = PsiModifier.PUBLIC;
|
||||
@@ -269,7 +268,7 @@ public class MoveMembersProcessor extends BaseRefactoringProcessor {
|
||||
String message =
|
||||
RefactoringBundle.message("0.with.1.visibility.is.not.accesible.from.2", RefactoringUIUtil.getDescription(member, true),
|
||||
newVisibility, RefactoringUIUtil.getDescription(ConflictsUtil.getContainer(element), true));
|
||||
conflicts.add(message);
|
||||
conflicts.put(member, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -289,8 +288,8 @@ public class MoveMembersProcessor extends BaseRefactoringProcessor {
|
||||
}
|
||||
|
||||
private boolean canRefactor() {
|
||||
final String[] conflicts = analyzeMoveConflicts(myMembersToMove, myTargetClass, myNewVisibility);
|
||||
if (conflicts.length > 0) {
|
||||
final Map<PsiElement, String> conflicts = analyzeMoveConflicts(myMembersToMove, myTargetClass, myNewVisibility);
|
||||
if (!conflicts.isEmpty()) {
|
||||
ConflictsDialog dialog = new ConflictsDialog(myProject, conflicts);
|
||||
dialog.show();
|
||||
return dialog.isOK();
|
||||
@@ -298,15 +297,15 @@ public class MoveMembersProcessor extends BaseRefactoringProcessor {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static String[] analyzeMoveConflicts(@NotNull Set<PsiMember> membersToMove, final PsiClass targetClass, final String newVisibility) {
|
||||
final LinkedHashSet<String> conflicts = new LinkedHashSet<String>();
|
||||
private static Map<PsiElement, String> analyzeMoveConflicts(@NotNull Set<PsiMember> membersToMove, final PsiClass targetClass, final String newVisibility) {
|
||||
final LinkedHashMap<PsiElement, String> conflicts = new LinkedHashMap<PsiElement, String>();
|
||||
for (final PsiMember member : membersToMove) {
|
||||
if (member instanceof PsiMethod) {
|
||||
PsiMethod method = (PsiMethod)member;
|
||||
if (hasMethod(targetClass, method)) {
|
||||
String message = RefactoringBundle.message("0.already.exists.in.the.target.class", RefactoringUIUtil.getDescription(method, false));
|
||||
message = CommonRefactoringUtil.capitalize(message);
|
||||
conflicts.add(message);
|
||||
conflicts.put(method, message);
|
||||
}
|
||||
}
|
||||
else if (member instanceof PsiField) {
|
||||
@@ -314,16 +313,16 @@ public class MoveMembersProcessor extends BaseRefactoringProcessor {
|
||||
if (hasField(targetClass, field)) {
|
||||
String message = RefactoringBundle.message("0.already.exists.in.the.target.class", RefactoringUIUtil.getDescription(field, false));
|
||||
message = CommonRefactoringUtil.capitalize(message);
|
||||
conflicts.add(message);
|
||||
conflicts.put(field, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
return analyzeAccessibilityConflicts(membersToMove, targetClass, conflicts, newVisibility);
|
||||
}
|
||||
|
||||
public static String[] analyzeAccessibilityConflicts(@NotNull Set<PsiMember> membersToMove,
|
||||
public static Map<PsiElement, String> analyzeAccessibilityConflicts(@NotNull Set<PsiMember> membersToMove,
|
||||
final PsiClass targetClass,
|
||||
final LinkedHashSet<String> conflicts, String newVisibility) {
|
||||
final LinkedHashMap<PsiElement, String> conflicts, String newVisibility) {
|
||||
if (VisibilityUtil.ESCALATE_VISIBILITY.equals(newVisibility)) { //Still need to check for access object
|
||||
newVisibility = PsiModifier.PUBLIC;
|
||||
}
|
||||
@@ -353,7 +352,7 @@ public class MoveMembersProcessor extends BaseRefactoringProcessor {
|
||||
VisibilityUtil.getVisibilityStringToDisplay(targetClass),
|
||||
RefactoringUIUtil.getDescription(ConflictsUtil.getContainer(ref), true));
|
||||
message = CommonRefactoringUtil.capitalize(message);
|
||||
conflicts.add(message);
|
||||
conflicts.put(targetClass, message);
|
||||
}
|
||||
//check for member accessibility
|
||||
else if (!manager.getResolveHelper().isAccessible(member, modifierList, ref, null, null)) {
|
||||
@@ -362,15 +361,15 @@ public class MoveMembersProcessor extends BaseRefactoringProcessor {
|
||||
VisibilityUtil.getVisibilityStringToDisplay(member),
|
||||
RefactoringUIUtil.getDescription(ConflictsUtil.getContainer(ref), true));
|
||||
message = CommonRefactoringUtil.capitalize(message);
|
||||
conflicts.add(message);
|
||||
conflicts.put(member, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ArrayUtil.toStringArray(conflicts);
|
||||
return conflicts;
|
||||
}
|
||||
|
||||
private static void checkUsedElements(PsiMember member, PsiElement scope, @NotNull Set<PsiMember> membersToMove, PsiClass newContext, LinkedHashSet<String> conflicts) {
|
||||
private static void checkUsedElements(PsiMember member, PsiElement scope, @NotNull Set<PsiMember> membersToMove, PsiClass newContext, LinkedHashMap<PsiElement, String> conflicts) {
|
||||
if(scope instanceof PsiReferenceExpression) {
|
||||
PsiReferenceExpression refExpr = (PsiReferenceExpression)scope;
|
||||
PsiElement refElement = refExpr.resolve();
|
||||
@@ -420,14 +419,14 @@ public class MoveMembersProcessor extends BaseRefactoringProcessor {
|
||||
PsiClass newContext,
|
||||
PsiClass accessClass,
|
||||
PsiMember member,
|
||||
LinkedHashSet<String> conflicts) {
|
||||
LinkedHashMap<PsiElement, String> conflicts) {
|
||||
if (!PsiUtil.isAccessible(refMember, newContext, accessClass)) {
|
||||
String message = RefactoringBundle.message("0.is.1.and.will.not.be.accessible.from.2.in.the.target.class",
|
||||
RefactoringUIUtil.getDescription(refMember, true),
|
||||
VisibilityUtil.getVisibilityStringToDisplay(refMember),
|
||||
RefactoringUIUtil.getDescription(member, false));
|
||||
message = CommonRefactoringUtil.capitalize(message);
|
||||
conflicts.add(message);
|
||||
conflicts.put(refMember, message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -18,8 +18,9 @@ import com.intellij.usageView.UsageViewDescriptor;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class RemoveMiddlemanProcessor extends FixableUsagesRefactoringProcessor {
|
||||
private static final Logger LOG = Logger.getInstance("#" + RemoveMiddlemanProcessor.class.getName());
|
||||
@@ -60,12 +61,12 @@ public class RemoveMiddlemanProcessor extends FixableUsagesRefactoringProcessor
|
||||
|
||||
@Override
|
||||
protected boolean preprocessUsages(final Ref<UsageInfo[]> refUsages) {
|
||||
final List<String> conflicts = new ArrayList<String>();
|
||||
final Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
|
||||
for (MemberInfo memberInfo : myDelegateMethodInfos) {
|
||||
if (memberInfo.isChecked() && memberInfo.isToAbstract()) {
|
||||
final PsiMember psiMember = memberInfo.getMember();
|
||||
if (psiMember instanceof PsiMethod && ((PsiMethod)psiMember).findDeepestSuperMethods().length > 0) {
|
||||
conflicts.add(SymbolPresentationUtil.getSymbolPresentableText(psiMember) + " will be deleted. Hierarchy will be broken");
|
||||
conflicts.put(psiMember, SymbolPresentationUtil.getSymbolPresentableText(psiMember) + " will be deleted. Hierarchy will be broken");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ public class RenameJavaClassProcessor extends RenamePsiElementProcessor {
|
||||
return WHITE_SPACE_PATTERN.matcher(s).replaceAll("");
|
||||
}
|
||||
|
||||
public void findExistingNameConflicts(final PsiElement element, final String newName, final Collection<String> conflicts) {
|
||||
public void findExistingNameConflicts(final PsiElement element, final String newName, final Map<PsiElement, String> conflicts) {
|
||||
if (element instanceof PsiCompiledElement) return;
|
||||
final PsiClass aClass = (PsiClass)element;
|
||||
if (newName.equals(aClass.getName())) return;
|
||||
@@ -196,7 +196,7 @@ public class RenameJavaClassProcessor extends RenamePsiElementProcessor {
|
||||
PsiClass[] innerClasses = containingClass.getInnerClasses();
|
||||
for (PsiClass innerClass : innerClasses) {
|
||||
if (newName.equals(innerClass.getName())) {
|
||||
conflicts.add(RefactoringBundle.message("inner.class.0.is.already.defined.in.class.1", newName, containingClass.getQualifiedName()));
|
||||
conflicts.put(innerClass, RefactoringBundle.message("inner.class.0.is.already.defined.in.class.1", newName, containingClass.getQualifiedName()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -207,7 +207,7 @@ public class RenameJavaClassProcessor extends RenamePsiElementProcessor {
|
||||
final PsiClass conflictingClass =
|
||||
JavaPsiFacade.getInstance(project).findClass(qualifiedNameAfterRename, GlobalSearchScope.allScope(project));
|
||||
if (conflictingClass != null) {
|
||||
conflicts.add(RefactoringBundle.message("class.0.already.exists", qualifiedNameAfterRename));
|
||||
conflicts.put(conflictingClass, RefactoringBundle.message("class.0.already.exists", qualifiedNameAfterRename));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ public class RenameJavaMethodProcessor extends RenameJavaMemberProcessor {
|
||||
findMemberHidesOuterMemberCollisions((PsiMethod) element, newName, result);
|
||||
}
|
||||
|
||||
public void findExistingNameConflicts(final PsiElement element, final String newName, final Collection<String> conflicts) {
|
||||
public void findExistingNameConflicts(final PsiElement element, final String newName, final Map<PsiElement, String> conflicts) {
|
||||
if (element instanceof PsiCompiledElement) return;
|
||||
PsiMethod refactoredMethod = (PsiMethod)element;
|
||||
if (newName.equals(refactoredMethod.getName())) return;
|
||||
|
||||
@@ -218,7 +218,7 @@ public class RenameJavaVariableProcessor extends RenameJavaMemberProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
public void findExistingNameConflicts(final PsiElement element, final String newName, final Collection<String> conflicts) {
|
||||
public void findExistingNameConflicts(final PsiElement element, final String newName, final Map<PsiElement, String> conflicts) {
|
||||
if (element instanceof PsiCompiledElement) return;
|
||||
if (element instanceof PsiField) {
|
||||
PsiField refactoredField = (PsiField)element;
|
||||
|
||||
@@ -12,7 +12,6 @@ import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -49,12 +48,13 @@ public class RenamePsiPackageProcessor extends RenamePsiElementProcessor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void findExistingNameConflicts(PsiElement element, String newName, Collection<String> conflicts) {
|
||||
public void findExistingNameConflicts(PsiElement element, String newName, Map<PsiElement, String> conflicts) {
|
||||
final PsiPackage aPackage = (PsiPackage)element;
|
||||
final Project project = element.getProject();
|
||||
final String qualifiedNameAfterRename = getPackageQualifiedNameAfterRename(aPackage, newName, true);
|
||||
if (JavaPsiFacade.getInstance(project).findClass(qualifiedNameAfterRename, GlobalSearchScope.allScope(project)) != null) {
|
||||
conflicts.add("Class with qualified name \'" + qualifiedNameAfterRename + "\' already exist");
|
||||
final PsiClass psiClass = JavaPsiFacade.getInstance(project).findClass(qualifiedNameAfterRename, GlobalSearchScope.allScope(project));
|
||||
if (psiClass != null) {
|
||||
conflicts.put(psiClass, "Class with qualified name \'" + qualifiedNameAfterRename + "\' already exist");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+7
-7
@@ -31,7 +31,7 @@ import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -251,30 +251,30 @@ public class ReplaceConstructorWithBuilderProcessor extends FixableUsagesRefacto
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean showConflicts(List<String> conflicts) {
|
||||
protected boolean showConflicts(Map<PsiElement, String> conflicts) {
|
||||
if (!conflicts.isEmpty() && ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
throw new RuntimeException(StringUtil.join(conflicts, "\n"));
|
||||
throw new RuntimeException(StringUtil.join(conflicts.values(), "\n"));
|
||||
}
|
||||
return super.showConflicts(conflicts);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean preprocessUsages(Ref<UsageInfo[]> refUsages) {
|
||||
final List<String> conflicts = new ArrayList<String>();
|
||||
final Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
|
||||
final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(myProject);
|
||||
final PsiClass builderClass =
|
||||
psiFacade.findClass(StringUtil.getQualifiedName(myPackageName, myClassName), GlobalSearchScope.projectScope(myProject));
|
||||
if (builderClass == null) {
|
||||
if (!myCreateNewBuilderClass) {
|
||||
conflicts.add("Selected class was not found.");
|
||||
conflicts.put(null, "Selected class was not found.");
|
||||
}
|
||||
} else if (myCreateNewBuilderClass){
|
||||
conflicts.add("Class with chosen name already exist.");
|
||||
conflicts.put(builderClass, "Class with chosen name already exist.");
|
||||
}
|
||||
|
||||
final PsiMethod commonConstructor = getMostCommonConstructor();
|
||||
if (commonConstructor == null) {
|
||||
conflicts.add("Found constructors are not reducible to simple chain");
|
||||
conflicts.put(null, "Found constructors are not reducible to simple chain");
|
||||
}
|
||||
|
||||
return showConflicts(conflicts);
|
||||
|
||||
+9
-7
@@ -114,13 +114,14 @@ public class ReplaceConstructorWithFactoryProcessor extends BaseRefactoringProce
|
||||
protected boolean preprocessUsages(Ref<UsageInfo[]> refUsages) {
|
||||
UsageInfo[] usages = refUsages.get();
|
||||
|
||||
ArrayList<String> conflicts = new ArrayList<String>();
|
||||
Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
|
||||
final PsiResolveHelper helper = JavaPsiFacade.getInstance(myProject).getResolveHelper();
|
||||
if (!helper.isAccessible(getConstructorContainingClass(), myTargetClass, null)) {
|
||||
final PsiClass constructorContainingClass = getConstructorContainingClass();
|
||||
if (!helper.isAccessible(constructorContainingClass, myTargetClass, null)) {
|
||||
String message = RefactoringBundle.message("class.0.is.not.accessible.from.target.1",
|
||||
RefactoringUIUtil.getDescription(getConstructorContainingClass(), true),
|
||||
RefactoringUIUtil.getDescription(constructorContainingClass, true),
|
||||
RefactoringUIUtil.getDescription(myTargetClass, true));
|
||||
conflicts.add(message);
|
||||
conflicts.put(constructorContainingClass, message);
|
||||
}
|
||||
|
||||
HashSet<PsiElement> reportedContainers = new HashSet<PsiElement>();
|
||||
@@ -133,7 +134,7 @@ public class ReplaceConstructorWithFactoryProcessor extends BaseRefactoringProce
|
||||
String message = RefactoringBundle.message("target.0.is.not.accessible.from.1",
|
||||
targetClassDescription,
|
||||
RefactoringUIUtil.getDescription(container, true));
|
||||
conflicts.add(message);
|
||||
conflicts.put(myTargetClass, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -146,8 +147,9 @@ public class ReplaceConstructorWithFactoryProcessor extends BaseRefactoringProce
|
||||
|
||||
if (PsiTreeUtil.isAncestor(containingClass, myTargetClass, true)) {
|
||||
String message = RefactoringBundle.message("constructor.being.refactored.is.used.in.initializer.of.0",
|
||||
RefactoringUIUtil.getDescription(field, true), RefactoringUIUtil.getDescription(getConstructorContainingClass(), false));
|
||||
conflicts.add(message);
|
||||
RefactoringUIUtil.getDescription(field, true), RefactoringUIUtil.getDescription(
|
||||
constructorContainingClass, false));
|
||||
conflicts.put(field, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import com.intellij.refactoring.RefactoringBundle;
|
||||
import com.intellij.usageView.UsageViewUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
public class ConflictsUtil {
|
||||
private ConflictsUtil() {
|
||||
@@ -31,7 +31,7 @@ public class ConflictsUtil {
|
||||
public static void checkMethodConflicts(@Nullable PsiClass aClass,
|
||||
PsiMethod refactoredMethod,
|
||||
PsiMethod prototype,
|
||||
final Collection<String> conflicts) {
|
||||
final Map<PsiElement,String> conflicts) {
|
||||
if (prototype == null) return;
|
||||
|
||||
PsiMethod method = aClass != null ? aClass.findMethodBySignature(prototype, true) : null;
|
||||
@@ -41,7 +41,7 @@ public class ConflictsUtil {
|
||||
final String classDescr = aClass instanceof PsiAnonymousClass ?
|
||||
RefactoringBundle.message("current.class") :
|
||||
RefactoringUIUtil.getDescription(aClass, false);
|
||||
conflicts.add(RefactoringBundle.message("method.0.is.already.defined.in.the.1",
|
||||
conflicts.put(method, RefactoringBundle.message("method.0.is.already.defined.in.the.1",
|
||||
getMethodPrototypeString(prototype),
|
||||
classDescr));
|
||||
}
|
||||
@@ -55,10 +55,10 @@ public class ConflictsUtil {
|
||||
final String conflict = isMethodAbstract != isMyMethodAbstract ?
|
||||
RefactoringBundle.message("method.0.will.implement.method.of.the.base.class", protoMethodInfo, className) :
|
||||
RefactoringBundle.message("method.0.will.override.a.method.of.the.base.class", protoMethodInfo, className);
|
||||
conflicts.add(conflict);
|
||||
conflicts.put(method, conflict);
|
||||
}
|
||||
else { // prototype is private, will be compile-error
|
||||
conflicts.add(RefactoringBundle.message("method.0.will.hide.method.of.the.base.class",
|
||||
conflicts.put(method, RefactoringBundle.message("method.0.will.hide.method.of.the.base.class",
|
||||
protoMethodInfo, className));
|
||||
}
|
||||
}
|
||||
@@ -74,7 +74,7 @@ public class ConflictsUtil {
|
||||
);
|
||||
}
|
||||
|
||||
public static void checkFieldConflicts(@Nullable PsiClass aClass, String newName, final Collection<String> conflicts) {
|
||||
public static void checkFieldConflicts(@Nullable PsiClass aClass, String newName, final Map<PsiElement, String> conflicts) {
|
||||
PsiField existingField = aClass != null ? aClass.findFieldByName(newName, true) : null;
|
||||
if (existingField != null) {
|
||||
if (aClass.equals(existingField.getContainingClass())) {
|
||||
@@ -83,7 +83,7 @@ public class ConflictsUtil {
|
||||
RefactoringUIUtil.getDescription(aClass, false);
|
||||
final String conflict = RefactoringBundle.message("field.0.is.already.defined.in.the.1",
|
||||
existingField.getName(), className);
|
||||
conflicts.add(conflict);
|
||||
conflicts.put(existingField, conflict);
|
||||
}
|
||||
else { // method somewhere in base class
|
||||
if (!existingField.hasModifierProperty(PsiModifier.PRIVATE)) {
|
||||
@@ -91,7 +91,7 @@ public class ConflictsUtil {
|
||||
String className = RefactoringUIUtil.getDescription(existingField.getContainingClass(), false);
|
||||
final String descr = RefactoringBundle.message("field.0.will.hide.field.1.of.the.base.class",
|
||||
newName, fieldInfo, className);
|
||||
conflicts.add(descr);
|
||||
conflicts.put(existingField, descr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -12,6 +12,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class FixableUsagesRefactoringProcessor extends BaseRefactoringProcessor {
|
||||
private static final Logger LOG = Logger.getInstance("#" + FixableUsagesRefactoringProcessor.class.getName());
|
||||
@@ -47,11 +48,11 @@ public abstract class FixableUsagesRefactoringProcessor extends BaseRefactoringP
|
||||
|
||||
protected abstract void findUsages(@NotNull List<FixableUsageInfo> usages);
|
||||
|
||||
protected static void checkConflicts(final Ref<UsageInfo[]> refUsages, final List<String> conflicts) {
|
||||
protected static void checkConflicts(final Ref<UsageInfo[]> refUsages, final Map<PsiElement, String> conflicts) {
|
||||
for (UsageInfo info : refUsages.get()) {
|
||||
final String conflict = ((FixableUsageInfo)info).getConflictMessage();
|
||||
if (conflict != null) {
|
||||
conflicts.add(XmlUtil.escape(conflict));
|
||||
conflicts.put(info.getElement(), XmlUtil.escape(conflict));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1092,7 +1092,7 @@ public class RefactoringUtil {
|
||||
Collection<? extends PsiElement> scope,
|
||||
final UsageInfo[] usages,
|
||||
PsiElement target,
|
||||
final Collection<String> conflicts) {
|
||||
final Map<PsiElement, String> conflicts) {
|
||||
if (scope == null) return;
|
||||
final VirtualFile vFile = PsiUtilBase.getVirtualFile(target);
|
||||
if (vFile == null) return;
|
||||
@@ -1103,7 +1103,7 @@ public class RefactoringUtil {
|
||||
final Collection<? extends PsiElement> scopes,
|
||||
final UsageInfo[] usages,
|
||||
final VirtualFile vFile,
|
||||
final Collection<String> conflicts) {
|
||||
final Map<PsiElement, String> conflicts) {
|
||||
if (scopes == null) return;
|
||||
|
||||
for (final PsiElement scope : scopes) {
|
||||
@@ -1128,7 +1128,7 @@ public class RefactoringUtil {
|
||||
RefactoringUIUtil.getDescription(resolved, true)), scopeDescription,
|
||||
CommonRefactoringUtil.htmlEmphasize(
|
||||
targetModule.getName()));
|
||||
conflicts.add(message);
|
||||
conflicts.put(resolved, message);
|
||||
reported.add(resolved);
|
||||
}
|
||||
}
|
||||
@@ -1164,21 +1164,22 @@ public class RefactoringUtil {
|
||||
Module module = ProjectRootManager.getInstance(project).getFileIndex().getModuleForFile(usageVFile);
|
||||
if (module != null) {
|
||||
final String message;
|
||||
final PsiElement referencedElement = moveRenameUsageInfo.getReferencedElement();
|
||||
if (module == targetModule && isInTestSources) {
|
||||
message = RefactoringBundle.message("0.referenced.in.1.will.not.be.accessible.from.production.of.module.2",
|
||||
CommonRefactoringUtil.capitalize(
|
||||
RefactoringUIUtil.getDescription(moveRenameUsageInfo.getReferencedElement(), true)),
|
||||
RefactoringUIUtil.getDescription(referencedElement, true)),
|
||||
scopeDescription,
|
||||
CommonRefactoringUtil.htmlEmphasize(module.getName()));
|
||||
}
|
||||
else {
|
||||
message = RefactoringBundle.message("0.referenced.in.1.will.not.be.accessible.from.module.2",
|
||||
CommonRefactoringUtil.capitalize(
|
||||
RefactoringUIUtil.getDescription(moveRenameUsageInfo.getReferencedElement(), true)),
|
||||
RefactoringUIUtil.getDescription(referencedElement, true)),
|
||||
scopeDescription,
|
||||
CommonRefactoringUtil.htmlEmphasize(module.getName()));
|
||||
}
|
||||
conflicts.add(message);
|
||||
conflicts.put(referencedElement, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+9
-11
@@ -33,10 +33,7 @@ import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
public class WrapReturnValueProcessor extends FixableUsagesRefactoringProcessor {
|
||||
|
||||
@@ -140,11 +137,11 @@ public class WrapReturnValueProcessor extends FixableUsagesRefactoringProcessor
|
||||
|
||||
@Override
|
||||
protected boolean preprocessUsages(final Ref<UsageInfo[]> refUsages) {
|
||||
List<String> conflicts = new ArrayList<String>();
|
||||
Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
|
||||
final PsiClass existingClass = JavaPsiFacade.getInstance(myProject).findClass(myQualifiedName);
|
||||
if (myUseExistingClass) {
|
||||
if (existingClass == null) {
|
||||
conflicts.add(RefactorJBundle.message("could.not.find.selected.wrapping.class"));
|
||||
conflicts.put(existingClass, RefactorJBundle.message("could.not.find.selected.wrapping.class"));
|
||||
}
|
||||
else {
|
||||
boolean foundConstructor = false;
|
||||
@@ -198,25 +195,26 @@ public class WrapReturnValueProcessor extends FixableUsagesRefactoringProcessor
|
||||
}
|
||||
}
|
||||
if (!foundConstructor) {
|
||||
conflicts.add("Existing class does not have appropriate constructor");
|
||||
conflicts.put(existingClass, "Existing class does not have appropriate constructor");
|
||||
}
|
||||
}
|
||||
if (unwrapMethodName.length() == 0) {
|
||||
conflicts.add("Existing class does not have getter for selected field");
|
||||
conflicts.put(existingClass,
|
||||
"Existing class does not have getter for selected field");
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (existingClass != null) {
|
||||
conflicts.add(RefactorJBundle.message("there.already.exists.a.class.with.the.selected.name"));
|
||||
conflicts.put(existingClass, RefactorJBundle.message("there.already.exists.a.class.with.the.selected.name"));
|
||||
}
|
||||
}
|
||||
return showConflicts(conflicts);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean showConflicts(final List<String> conflicts) {
|
||||
protected boolean showConflicts(final Map<PsiElement,String> conflicts) {
|
||||
if (!conflicts.isEmpty() && ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
throw new RuntimeException(StringUtil.join(conflicts, "\n"));
|
||||
throw new RuntimeException(StringUtil.join(conflicts.values(), "\n"));
|
||||
}
|
||||
return super.showConflicts(conflicts);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user