mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 03:21:12 +07:00
show conflicts unification;
encapsulate fields: rise conflicts; tests
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* User: anna
|
||||
* Date: 23-Oct-2009
|
||||
*/
|
||||
package com.intellij.refactoring.encapsulateFields;
|
||||
|
||||
import com.intellij.psi.Modifier;
|
||||
import com.intellij.psi.PsiField;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface EncapsulateFieldsDescriptor {
|
||||
PsiField[] getSelectedFields();
|
||||
|
||||
String[] getGetterNames();
|
||||
|
||||
String[] getSetterNames();
|
||||
|
||||
@Nullable
|
||||
PsiMethod[] getGetterPrototypes();
|
||||
|
||||
@Nullable
|
||||
PsiMethod[] getSetterPrototypes();
|
||||
|
||||
boolean isToEncapsulateGet();
|
||||
|
||||
boolean isToEncapsulateSet();
|
||||
|
||||
boolean isToUseAccessorsWhenAccessible();
|
||||
|
||||
@Modifier
|
||||
String getFieldsVisibility();
|
||||
|
||||
@Modifier
|
||||
String getAccessorsVisibility();
|
||||
}
|
||||
@@ -47,7 +47,7 @@ import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.Set;
|
||||
|
||||
public class EncapsulateFieldsDialog extends RefactoringDialog {
|
||||
public class EncapsulateFieldsDialog extends RefactoringDialog implements EncapsulateFieldsDescriptor {
|
||||
private static final Logger LOG = Logger.getInstance(
|
||||
"#com.intellij.refactoring.encapsulateFields.EncapsulateFieldsDialog"
|
||||
);
|
||||
@@ -487,6 +487,11 @@ public String getAccessorsVisibility() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean areButtonsValid() {
|
||||
return getCheckedRows().length > 0;
|
||||
}
|
||||
|
||||
private PsiMethod generateMethodPrototype(PsiField field, String methodName, boolean isGetter) {
|
||||
PsiMethod prototype = isGetter
|
||||
? PropertyUtil.generateGetterPrototype(field)
|
||||
|
||||
@@ -23,15 +23,17 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.searches.ClassInheritorsSearch;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.psi.util.PsiFormatUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.refactoring.BaseRefactoringProcessor;
|
||||
import com.intellij.refactoring.HelpID;
|
||||
import com.intellij.refactoring.RefactoringBundle;
|
||||
import com.intellij.refactoring.ui.ConflictsDialog;
|
||||
import com.intellij.refactoring.util.CommonRefactoringUtil;
|
||||
import com.intellij.refactoring.util.RefactoringUIUtil;
|
||||
import com.intellij.refactoring.util.RefactoringUtil;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.usageView.UsageViewDescriptor;
|
||||
@@ -44,23 +46,24 @@ import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
public class EncapsulateFieldsProcessor extends BaseRefactoringProcessor {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.encapsulateFields.EncapsulateFieldsProcessor");
|
||||
|
||||
private PsiClass myClass;
|
||||
private final EncapsulateFieldsDialog myDialog;
|
||||
@NotNull
|
||||
private final EncapsulateFieldsDescriptor myDescriptor;
|
||||
private PsiField[] myFields;
|
||||
|
||||
private HashMap<String,PsiMethod> myNameToGetter;
|
||||
private HashMap<String,PsiMethod> myNameToSetter;
|
||||
|
||||
public EncapsulateFieldsProcessor(Project project, EncapsulateFieldsDialog dialog) {
|
||||
public EncapsulateFieldsProcessor(Project project, @NotNull EncapsulateFieldsDescriptor descriptor) {
|
||||
super(project);
|
||||
myDialog = dialog;
|
||||
myDescriptor = descriptor;
|
||||
myFields = myDescriptor.getSelectedFields();
|
||||
myClass = myFields[0].getContainingClass();
|
||||
}
|
||||
|
||||
protected UsageViewDescriptor createUsageViewDescriptor(UsageInfo[] usages) {
|
||||
@@ -73,37 +76,54 @@ public class EncapsulateFieldsProcessor extends BaseRefactoringProcessor {
|
||||
return RefactoringBundle.message("encapsulate.fields.command.name", UsageViewUtil.getDescriptiveName(myClass));
|
||||
}
|
||||
|
||||
public void doRun() {
|
||||
myFields = myDialog.getSelectedFields();
|
||||
if (myFields.length == 0){
|
||||
String message = RefactoringBundle.message("encapsulate.fields.no.fields.selected");
|
||||
CommonRefactoringUtil.showErrorMessage(EncapsulateFieldsHandler.REFACTORING_NAME, message, HelpID.ENCAPSULATE_FIELDS, myProject);
|
||||
return;
|
||||
}
|
||||
myClass = myFields[0].getContainingClass();
|
||||
|
||||
super.doRun();
|
||||
}
|
||||
|
||||
protected boolean preprocessUsages(Ref<UsageInfo[]> refUsages) {
|
||||
MultiMap<PsiElement, String> conflicts = new MultiMap<PsiElement, String>();
|
||||
final MultiMap<PsiElement, String> conflicts = new MultiMap<PsiElement, String>();
|
||||
|
||||
if (myDialog != null) {
|
||||
checkExistingMethods(myDialog.getGetterPrototypes(), conflicts, true);
|
||||
checkExistingMethods(myDialog.getSetterPrototypes(), conflicts, false);
|
||||
checkExistingMethods(myDescriptor.getGetterPrototypes(), conflicts, true);
|
||||
checkExistingMethods(myDescriptor.getSetterPrototypes(), conflicts, false);
|
||||
final Collection<PsiClass> classes = ClassInheritorsSearch.search(myClass).findAll();
|
||||
for (int i = 0; i < myFields.length; i++) {
|
||||
final PsiField field = myFields[i];
|
||||
final Set<PsiMethod> setters = new HashSet<PsiMethod>();
|
||||
final Set<PsiMethod> getters = new HashSet<PsiMethod>();
|
||||
|
||||
if(conflicts.size() > 0) {
|
||||
ConflictsDialog dialog = new ConflictsDialog(myProject, conflicts);
|
||||
dialog.show();
|
||||
if(!dialog.isOK()){
|
||||
if (dialog.isShowConflicts()) prepareSuccessful();
|
||||
return false;
|
||||
for (PsiClass aClass : classes) {
|
||||
final PsiMethod getterOverrider = aClass.findMethodBySignature(myDescriptor.getGetterPrototypes()[i], false);
|
||||
if (getterOverrider != null) {
|
||||
getters.add(getterOverrider);
|
||||
}
|
||||
final PsiMethod setterOverrider = aClass.findMethodBySignature(myDescriptor.getSetterPrototypes()[i], false);
|
||||
if (setterOverrider != null) {
|
||||
setters.add(setterOverrider);
|
||||
}
|
||||
}
|
||||
if (!getters.isEmpty() || !setters.isEmpty()) {
|
||||
for (PsiReference reference : ReferencesSearch.search(field)) {
|
||||
final PsiElement place = reference.getElement();
|
||||
LOG.assertTrue(place instanceof PsiReferenceExpression);
|
||||
final PsiExpression qualifierExpression = ((PsiReferenceExpression)place).getQualifierExpression();
|
||||
final PsiClass ancestor;
|
||||
if (qualifierExpression == null) {
|
||||
ancestor = PsiTreeUtil.getParentOfType(place, PsiClass.class, false);
|
||||
}
|
||||
else {
|
||||
ancestor = PsiUtil.resolveClassInType(qualifierExpression.getType());
|
||||
}
|
||||
|
||||
final boolean isGetter = !PsiUtil.isAccessedForWriting((PsiExpression)place);
|
||||
for (PsiMethod overridden : isGetter ? getters : setters) {
|
||||
if (InheritanceUtil.isInheritorOrSelf(myClass, ancestor, true)) {
|
||||
conflicts.putValue(overridden, "There is already a " +
|
||||
CommonRefactoringUtil.htmlEmphasize(RefactoringUIUtil.getDescription(overridden, true)) +
|
||||
" which would hide generated " +
|
||||
(isGetter ? "getter" : "setter") + " for " + place.getText());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
prepareSuccessful();
|
||||
return true;
|
||||
return showConflicts(conflicts);
|
||||
}
|
||||
|
||||
private void checkExistingMethods(PsiMethod[] prototypes, MultiMap<PsiElement, String> conflicts, boolean isGetter) {
|
||||
@@ -126,16 +146,40 @@ public class EncapsulateFieldsProcessor extends BaseRefactoringProcessor {
|
||||
CommonRefactoringUtil.htmlEmphasize(prototype.getName()));
|
||||
conflicts.putValue(existing, message);
|
||||
}
|
||||
} else {
|
||||
PsiClass containingClass = myClass.getContainingClass();
|
||||
while (containingClass != null && existing == null) {
|
||||
existing = containingClass.findMethodBySignature(prototype, true);
|
||||
if (existing != null) {
|
||||
for (PsiReference reference : ReferencesSearch.search(existing)) {
|
||||
final PsiElement place = reference.getElement();
|
||||
LOG.assertTrue(place instanceof PsiReferenceExpression);
|
||||
final PsiExpression qualifierExpression = ((PsiReferenceExpression)place).getQualifierExpression();
|
||||
final PsiClass inheritor;
|
||||
if (qualifierExpression == null) {
|
||||
inheritor = PsiTreeUtil.getParentOfType(place, PsiClass.class, false);
|
||||
} else {
|
||||
inheritor = PsiUtil.resolveClassInType(qualifierExpression.getType());
|
||||
}
|
||||
|
||||
if (InheritanceUtil.isInheritorOrSelf(inheritor, myClass, true)) {
|
||||
conflicts.putValue(existing, "There is already a " + CommonRefactoringUtil.htmlEmphasize(RefactoringUIUtil.getDescription(existing, true)) + " which would be hidden by generated " + (isGetter ? "getter" : "setter"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
containingClass = containingClass.getContainingClass();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull protected UsageInfo[] findUsages() {
|
||||
boolean findGet = myDialog.isToEncapsulateGet();
|
||||
boolean findSet = myDialog.isToEncapsulateSet();
|
||||
boolean findGet = myDescriptor.isToEncapsulateGet();
|
||||
boolean findSet = myDescriptor.isToEncapsulateSet();
|
||||
PsiModifierList newModifierList = null;
|
||||
final JavaPsiFacade facade = JavaPsiFacade.getInstance(myProject);
|
||||
if (!myDialog.isToUseAccessorsWhenAccessible()){
|
||||
if (!myDescriptor.isToUseAccessorsWhenAccessible()){
|
||||
PsiElementFactory factory = facade.getElementFactory();
|
||||
try{
|
||||
PsiField field = factory.createField("a", PsiType.INT);
|
||||
@@ -146,8 +190,8 @@ public class EncapsulateFieldsProcessor extends BaseRefactoringProcessor {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
PsiMethod[] getterPrototypes = myDialog.getGetterPrototypes();
|
||||
PsiMethod[] setterPrototypes = myDialog.getSetterPrototypes();
|
||||
PsiMethod[] getterPrototypes = myDescriptor.getGetterPrototypes();
|
||||
PsiMethod[] setterPrototypes = myDescriptor.getSetterPrototypes();
|
||||
ArrayList<UsageInfo> array = new ArrayList<UsageInfo>();
|
||||
PsiField[] fields = myFields;
|
||||
for(int i = 0; i < fields.length; i++){
|
||||
@@ -164,7 +208,7 @@ public class EncapsulateFieldsProcessor extends BaseRefactoringProcessor {
|
||||
if (!findSet || field.hasModifierProperty(PsiModifier.FINAL)) {
|
||||
if (!PsiUtil.isAccessedForReading(ref)) continue;
|
||||
}
|
||||
if (!myDialog.isToUseAccessorsWhenAccessible()) {
|
||||
if (!myDescriptor.isToUseAccessorsWhenAccessible()) {
|
||||
PsiClass accessObjectClass = null;
|
||||
PsiExpression qualifier = ref.getQualifierExpression();
|
||||
if (qualifier != null) {
|
||||
@@ -199,7 +243,7 @@ public class EncapsulateFieldsProcessor extends BaseRefactoringProcessor {
|
||||
|
||||
protected void performRefactoring(UsageInfo[] usages) {
|
||||
// change visibility of fields
|
||||
if (myDialog.getFieldsVisibility() != null){
|
||||
if (myDescriptor.getFieldsVisibility() != null){
|
||||
// "as is"
|
||||
for (PsiField field : myFields) {
|
||||
setNewFieldVisibility(field);
|
||||
@@ -207,16 +251,18 @@ public class EncapsulateFieldsProcessor extends BaseRefactoringProcessor {
|
||||
}
|
||||
|
||||
// generate accessors
|
||||
myNameToGetter = new com.intellij.util.containers.HashMap<String, PsiMethod>();
|
||||
myNameToSetter = new com.intellij.util.containers.HashMap<String, PsiMethod>();
|
||||
myNameToGetter = new HashMap<String, PsiMethod>();
|
||||
myNameToSetter = new HashMap<String, PsiMethod>();
|
||||
for(int i = 0; i < myFields.length; i++){
|
||||
PsiField field = myFields[i];
|
||||
if (myDialog.isToEncapsulateGet()){
|
||||
PsiMethod[] prototypes = myDialog.getGetterPrototypes();
|
||||
if (myDescriptor.isToEncapsulateGet()){
|
||||
PsiMethod[] prototypes = myDescriptor.getGetterPrototypes();
|
||||
assert prototypes != null;
|
||||
addOrChangeAccessor(prototypes[i], myNameToGetter);
|
||||
}
|
||||
if (myDialog.isToEncapsulateSet() && !field.hasModifierProperty(PsiModifier.FINAL)){
|
||||
PsiMethod[] prototypes = myDialog.getSetterPrototypes();
|
||||
if (myDescriptor.isToEncapsulateSet() && !field.hasModifierProperty(PsiModifier.FINAL)){
|
||||
PsiMethod[] prototypes = myDescriptor.getSetterPrototypes();
|
||||
assert prototypes != null;
|
||||
addOrChangeAccessor(prototypes[i], myNameToSetter);
|
||||
}
|
||||
}
|
||||
@@ -246,9 +292,9 @@ public class EncapsulateFieldsProcessor extends BaseRefactoringProcessor {
|
||||
|
||||
private void setNewFieldVisibility(PsiField field) {
|
||||
try{
|
||||
if (myDialog.getFieldsVisibility() != null){
|
||||
if (myDescriptor.getFieldsVisibility() != null){
|
||||
field.normalizeDeclaration();
|
||||
PsiUtil.setModifierProperty(field, myDialog.getFieldsVisibility(), true);
|
||||
PsiUtil.setModifierProperty(field, myDescriptor.getFieldsVisibility(), true);
|
||||
}
|
||||
}
|
||||
catch(IncorrectOperationException e){
|
||||
@@ -261,7 +307,7 @@ public class EncapsulateFieldsProcessor extends BaseRefactoringProcessor {
|
||||
PsiMethod result = existing;
|
||||
try{
|
||||
if (existing == null){
|
||||
PsiUtil.setModifierProperty(prototype, myDialog.getAccessorsVisibility(), true);
|
||||
PsiUtil.setModifierProperty(prototype, myDescriptor.getAccessorsVisibility(), true);
|
||||
result = (PsiMethod) myClass.add(prototype);
|
||||
}
|
||||
else{
|
||||
@@ -288,8 +334,8 @@ public class EncapsulateFieldsProcessor extends BaseRefactoringProcessor {
|
||||
|
||||
private void processUsage(MyUsageInfo usage) {
|
||||
PsiField field = myFields[usage.fieldIndex];
|
||||
boolean processGet = myDialog.isToEncapsulateGet();
|
||||
boolean processSet = myDialog.isToEncapsulateSet() && !field.hasModifierProperty(PsiModifier.FINAL);
|
||||
boolean processGet = myDescriptor.isToEncapsulateGet();
|
||||
boolean processSet = myDescriptor.isToEncapsulateSet() && !field.hasModifierProperty(PsiModifier.FINAL);
|
||||
if (!processGet && !processSet) return;
|
||||
PsiElementFactory factory = JavaPsiFacade.getInstance(myProject).getElementFactory();
|
||||
|
||||
@@ -425,7 +471,7 @@ public class EncapsulateFieldsProcessor extends BaseRefactoringProcessor {
|
||||
}
|
||||
|
||||
private PsiMethodCallExpression createSetterCall(final int fieldIndex, final PsiExpression setterArgument, PsiReferenceExpression expr) throws IncorrectOperationException {
|
||||
String[] setterNames = myDialog.getSetterNames();
|
||||
String[] setterNames = myDescriptor.getSetterNames();
|
||||
PsiElementFactory factory = JavaPsiFacade.getInstance(expr.getProject()).getElementFactory();
|
||||
final String setterName = setterNames[fieldIndex];
|
||||
@NonNls String text = setterName + "(a)";
|
||||
@@ -451,7 +497,7 @@ public class EncapsulateFieldsProcessor extends BaseRefactoringProcessor {
|
||||
@Nullable
|
||||
private PsiMethodCallExpression createGetterCall(final int fieldIndex, PsiReferenceExpression expr)
|
||||
throws IncorrectOperationException {
|
||||
String[] getterNames = myDialog.getGetterNames();
|
||||
String[] getterNames = myDescriptor.getGetterNames();
|
||||
PsiElementFactory factory = JavaPsiFacade.getInstance(expr.getProject()).getElementFactory();
|
||||
final String getterName = getterNames[fieldIndex];
|
||||
@NonNls String text = getterName + "()";
|
||||
@@ -509,4 +555,4 @@ public class EncapsulateFieldsProcessor extends BaseRefactoringProcessor {
|
||||
this.fieldIndex = fieldIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,14 +148,7 @@ public class ExtractClassProcessor extends FixableUsagesRefactoringProcessor {
|
||||
return showConflicts(conflicts);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean showConflicts(final MultiMap<PsiElement, String> conflicts) {
|
||||
if (!conflicts.isEmpty() && ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
throw new RuntimeException(StringUtil.join(conflicts.values(), "\n"));
|
||||
}
|
||||
return super.showConflicts(conflicts);
|
||||
}
|
||||
|
||||
|
||||
private void calculateInitializersConflicts(MultiMap<PsiElement, String> conflicts) {
|
||||
final PsiClassInitializer[] initializers = sourceClass.getInitializers();
|
||||
for (PsiClassInitializer initializer : initializers) {
|
||||
|
||||
@@ -42,7 +42,6 @@ import com.intellij.refactoring.BaseRefactoringProcessor;
|
||||
import com.intellij.refactoring.RefactoringBundle;
|
||||
import com.intellij.refactoring.introduceParameter.Util;
|
||||
import com.intellij.refactoring.rename.RenameJavaVariableProcessor;
|
||||
import com.intellij.refactoring.ui.ConflictsDialog;
|
||||
import com.intellij.refactoring.util.*;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.usageView.UsageViewDescriptor;
|
||||
@@ -139,21 +138,10 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
|
||||
|
||||
addInaccessibleSuperCallsConflicts(usagesIn, conflicts);
|
||||
|
||||
if (!conflicts.isEmpty()) {
|
||||
ConflictsDialog dialog = new ConflictsDialog(myProject, conflicts);
|
||||
dialog.show();
|
||||
if (!dialog.isOK()) {
|
||||
if (dialog.isShowConflicts()) prepareSuccessful();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!myInlineThisOnly) {
|
||||
if (!CommonRefactoringUtil.checkReadOnlyStatus(myProject, myMethod)) return false;
|
||||
}
|
||||
|
||||
prepareSuccessful();
|
||||
return true;
|
||||
return showConflicts(conflicts);
|
||||
}
|
||||
|
||||
private void addInaccessibleSuperCallsConflicts(final UsageInfo[] usagesIn, final MultiMap<PsiElement, String> conflicts) {
|
||||
|
||||
@@ -20,11 +20,9 @@
|
||||
*/
|
||||
package com.intellij.refactoring.inlineSuperClass;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
@@ -183,17 +181,14 @@ public class InlineSuperClassRefactoringProcessor extends FixableUsagesRefactori
|
||||
return showConflicts(conflicts);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean showConflicts(final MultiMap<PsiElement, String> conflicts) {
|
||||
if (!conflicts.isEmpty() && ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
throw new RuntimeException(StringUtil.join(conflicts.values(), "\n"));
|
||||
}
|
||||
return super.showConflicts(conflicts);
|
||||
}
|
||||
|
||||
|
||||
protected void performRefactoring(final UsageInfo[] usages) {
|
||||
new PushDownProcessor(mySuperClass.getProject(), myMemberInfos, mySuperClass, new DocCommentPolicy(DocCommentPolicy.ASIS)).run();
|
||||
new PushDownProcessor(mySuperClass.getProject(), myMemberInfos, mySuperClass, new DocCommentPolicy(DocCommentPolicy.ASIS)){
|
||||
//push down conflicts are already collected
|
||||
@Override
|
||||
protected boolean showConflicts(MultiMap<PsiElement, String> conflicts) {
|
||||
return true;
|
||||
}
|
||||
}.run();
|
||||
replaceInnerTypeUsages();
|
||||
super.performRefactoring(usages);
|
||||
try {
|
||||
|
||||
@@ -141,14 +141,6 @@ public class IntroduceParameterObjectProcessor extends FixableUsagesRefactoringP
|
||||
return showConflicts(conflicts);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean showConflicts(final MultiMap<PsiElement, String> conflicts) {
|
||||
if (!conflicts.isEmpty() && ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
throw new RuntimeException(StringUtil.join(conflicts.values(), "\n"));
|
||||
}
|
||||
return super.showConflicts(conflicts);
|
||||
}
|
||||
|
||||
public void findUsages(@NotNull List<FixableUsageInfo> usages) {
|
||||
if (myUseExistingClass && existingClass != null) {
|
||||
myExistingClassCompatible = existingClassIsCompatible(existingClass, parameters, getterNames);
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
package com.intellij.refactoring.replaceConstructorWithBuilder;
|
||||
|
||||
import com.intellij.ide.util.PackageUtil;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -266,14 +265,7 @@ public class ReplaceConstructorWithBuilderProcessor extends FixableUsagesRefacto
|
||||
return "create" + StringUtil.capitalize(myConstructors[0].getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean showConflicts(MultiMap<PsiElement, String> conflicts) {
|
||||
if (!conflicts.isEmpty() && ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
throw new RuntimeException(StringUtil.join(conflicts.values(), "\n"));
|
||||
}
|
||||
return super.showConflicts(conflicts);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean preprocessUsages(Ref<UsageInfo[]> refUsages) {
|
||||
final MultiMap<PsiElement, String> conflicts = new MultiMap<PsiElement, String>();
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package com.intellij.refactoring.wrapreturnvalue;
|
||||
|
||||
import com.intellij.ide.util.PackageUtil;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleUtil;
|
||||
@@ -49,7 +48,10 @@ import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class WrapReturnValueProcessor extends FixableUsagesRefactoringProcessor {
|
||||
|
||||
@@ -227,15 +229,6 @@ public class WrapReturnValueProcessor extends FixableUsagesRefactoringProcessor
|
||||
return showConflicts(conflicts);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean showConflicts(final MultiMap<PsiElement, String> conflicts) {
|
||||
if (!conflicts.isEmpty() && ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
throw new RuntimeException(StringUtil.join(conflicts.values(), "\n"));
|
||||
}
|
||||
return super.showConflicts(conflicts);
|
||||
}
|
||||
|
||||
|
||||
protected void performRefactoring(UsageInfo[] usageInfos) {
|
||||
if (!myUseExistingClass && !buildClass()) return;
|
||||
super.performRefactoring(usageInfos);
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
class Test {
|
||||
int i;
|
||||
int getI() {
|
||||
return i;
|
||||
}
|
||||
|
||||
void foo() {
|
||||
setI(getI() + 1);
|
||||
System.out.println(getI());
|
||||
|
||||
Test t;
|
||||
setI(t.getI());
|
||||
}
|
||||
|
||||
public void setI(int i) {
|
||||
this.i = i;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
class Test {
|
||||
int i;
|
||||
int getI() {
|
||||
return i;
|
||||
}
|
||||
|
||||
void foo() {
|
||||
i++;
|
||||
System.out.println(getI());
|
||||
|
||||
Test t;
|
||||
i = t.i;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
class Test {
|
||||
int i;
|
||||
int getI() {
|
||||
return i;
|
||||
}
|
||||
|
||||
Test setI(int i) {
|
||||
this.i = i;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
class Test {
|
||||
int i;
|
||||
int getI() {
|
||||
return i;
|
||||
}
|
||||
|
||||
Test setI(int i) {
|
||||
this.i = i;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
public class Test extends Super{
|
||||
int i;
|
||||
int getI() {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
class Super {
|
||||
Super setI(int i) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
public class Test extends Super{
|
||||
int i;
|
||||
int getI() {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
class Super {
|
||||
Super setI(int i) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,6 @@
|
||||
class Test implements I {
|
||||
A myField;
|
||||
void foo() {
|
||||
myField.foo();
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,11 @@ class Test implements I {
|
||||
return myField;
|
||||
}
|
||||
|
||||
void bar(I i) {
|
||||
void foo() {
|
||||
myField.foo();
|
||||
}
|
||||
|
||||
void bar(I i) {
|
||||
i.foo();
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,11 @@ class Test implements I {
|
||||
return myField;
|
||||
}
|
||||
|
||||
void bar(I i) {
|
||||
void foo() {
|
||||
myField.foo();
|
||||
}
|
||||
|
||||
void bar(I i) {
|
||||
i.foo();
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,6 @@ class D {
|
||||
}
|
||||
|
||||
void bazz(Test t){
|
||||
t.getMyField().foo();
|
||||
t.foo();
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
class Test extends A {
|
||||
D myField;
|
||||
|
||||
void ff(){
|
||||
myField.foo();
|
||||
void foo(){
|
||||
myField.foo();
|
||||
}
|
||||
|
||||
public D getMyField() {
|
||||
return myField;
|
||||
}
|
||||
void ff(){
|
||||
foo();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* User: anna
|
||||
* Date: 20-Aug-2008
|
||||
*/
|
||||
package com.intellij.refactoring;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.PropertyUtil;
|
||||
import com.intellij.refactoring.encapsulateFields.EncapsulateFieldsDescriptor;
|
||||
import com.intellij.refactoring.encapsulateFields.EncapsulateFieldsProcessor;
|
||||
import junit.framework.Assert;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class EncapsulateFieldsTest extends MultiFileTestCase{
|
||||
public void testAlreadyExist() throws Exception {
|
||||
doTest("i" , null);
|
||||
}
|
||||
|
||||
public void testDiffWithReturnTypeOnly() throws Exception {
|
||||
doTest("i", "There already is a method <b><code>Test setI(int)</code></b> which differs from setter <b><code>setI</code></b> by return type only.");
|
||||
}
|
||||
|
||||
public void testDiffWithReturnTypeOnlyInHierarchy() throws Exception {
|
||||
doTest("i", "There already is a method <b><code>Super setI(int)</code></b> which differs from setter <b><code>setI</code></b> by return type only.");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath();
|
||||
}
|
||||
|
||||
protected String getTestRoot() {
|
||||
return "/refactoring/encapsulateFields/";
|
||||
}
|
||||
|
||||
|
||||
private void doTest(final String fieldName, final String conflicts) throws Exception {
|
||||
doTest(new PerformAction() {
|
||||
public void performAction(final VirtualFile rootDir, final VirtualFile rootAfter) throws Exception {
|
||||
PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(myProject));
|
||||
|
||||
assertNotNull("Class Test not found", aClass);
|
||||
|
||||
|
||||
doTest(aClass, aClass.findFieldByName(fieldName, false), conflicts, true, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static void doTest(final PsiClass aClass, final PsiField field, final String conflicts,
|
||||
final boolean generateGetters, final boolean generateSetters) {
|
||||
try {
|
||||
final Project project = aClass.getProject();
|
||||
EncapsulateFieldsProcessor processor = new EncapsulateFieldsProcessor(project, new EncapsulateFieldsDescriptor() {
|
||||
public PsiField[] getSelectedFields() {
|
||||
return new PsiField[]{field};
|
||||
}
|
||||
|
||||
public String[] getGetterNames() {
|
||||
return new String[]{PropertyUtil.suggestGetterName(project, field)};
|
||||
}
|
||||
|
||||
public String[] getSetterNames() {
|
||||
return new String[]{PropertyUtil.suggestSetterName(project, field)};
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PsiMethod[] getGetterPrototypes() {
|
||||
return isToEncapsulateGet() ? new PsiMethod[]{PropertyUtil.generateGetterPrototype(field)} : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PsiMethod[] getSetterPrototypes() {
|
||||
return isToEncapsulateSet() ? new PsiMethod[]{PropertyUtil.generateSetterPrototype(field)} : null;
|
||||
}
|
||||
|
||||
public boolean isToEncapsulateGet() {
|
||||
return generateGetters;
|
||||
}
|
||||
|
||||
public boolean isToEncapsulateSet() {
|
||||
return generateSetters;
|
||||
}
|
||||
|
||||
public boolean isToUseAccessorsWhenAccessible() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Modifier
|
||||
public String getFieldsVisibility() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Modifier
|
||||
public String getAccessorsVisibility() {
|
||||
return PsiModifier.PUBLIC;
|
||||
}
|
||||
});
|
||||
processor.run();
|
||||
LocalFileSystem.getInstance().refresh(false);
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (conflicts != null) {
|
||||
Assert.assertEquals(conflicts, e.getMessage());
|
||||
return;
|
||||
} else {
|
||||
e.printStackTrace();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
if (conflicts != null) {
|
||||
fail("Conflicts were not detected: " + conflicts);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,12 +4,12 @@
|
||||
*/
|
||||
package com.intellij.refactoring;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.refactoring.inlineSuperClass.InlineSuperClassRefactoringProcessor;
|
||||
import com.intellij.JavaTestUtil;
|
||||
|
||||
public class InlineSuperClassTest extends MultiFileTestCase {
|
||||
protected String getTestRoot() {
|
||||
|
||||
@@ -31,12 +31,28 @@ public class IntroduceParameterTest extends LightCodeInsightTestCase {
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath();
|
||||
}
|
||||
|
||||
|
||||
private void doTest(int replaceFieldsWithGetters, boolean removeUnusedParameters, boolean searchForSuper, boolean declareFinal,
|
||||
final boolean generateDelegate) throws Exception {
|
||||
configureByFile("/refactoring/introduceParameter/before" + getTestName(false) + ".java");
|
||||
perform(true, replaceFieldsWithGetters, "anObject", searchForSuper, declareFinal, removeUnusedParameters, generateDelegate);
|
||||
checkResultByFile("/refactoring/introduceParameter/after" + getTestName(false) + ".java");
|
||||
doTest(replaceFieldsWithGetters, removeUnusedParameters, searchForSuper, declareFinal, generateDelegate, null);
|
||||
}
|
||||
|
||||
private void doTest(int replaceFieldsWithGetters, boolean removeUnusedParameters, boolean searchForSuper, boolean declareFinal, final boolean generateDelegate,
|
||||
String conflict) throws Exception {
|
||||
try {
|
||||
configureByFile("/refactoring/introduceParameter/before" + getTestName(false) + ".java");
|
||||
perform(true, replaceFieldsWithGetters, "anObject", searchForSuper, declareFinal, removeUnusedParameters, generateDelegate);
|
||||
checkResultByFile("/refactoring/introduceParameter/after" + getTestName(false) + ".java");
|
||||
if (conflict != null) {
|
||||
fail("Conflict expected");
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (conflict == null) {
|
||||
throw e;
|
||||
}
|
||||
assertEquals(conflict, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void testNoUsages() throws Exception {
|
||||
@@ -60,7 +76,7 @@ public class IntroduceParameterTest extends LightCodeInsightTestCase {
|
||||
}
|
||||
|
||||
public void testThisSubstitutionInQualifier() throws Exception {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false, false, false);
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false, false, false, "field <b><code>Test.i</code></b> is not accesible from method <b><code>XTest.n()</code></b>. Value for introduced parameter in that method call will be incorrect.");
|
||||
}
|
||||
|
||||
public void testFieldAccess() throws Exception {
|
||||
@@ -88,7 +104,7 @@ public class IntroduceParameterTest extends LightCodeInsightTestCase {
|
||||
}
|
||||
|
||||
public void testSuperInExpression() throws Exception {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE, false, false, false, false);
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE, false, false, false, false, "Parameter initializer contains <b><code>super</code></b>, but not all calls to method are in its class.");
|
||||
}
|
||||
|
||||
public void testNull() throws Exception {
|
||||
@@ -124,7 +140,7 @@ public class IntroduceParameterTest extends LightCodeInsightTestCase {
|
||||
}
|
||||
|
||||
public void testSuperWithSideEffect() throws Exception {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE, false, false, false, false);
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE, false, false, false, false, "Parameter initializer contains <b><code>super</code></b>, but not all calls to method are in its class.");
|
||||
}
|
||||
|
||||
public void testConflictingField() throws Exception {
|
||||
|
||||
@@ -54,7 +54,13 @@ public class MoveClassTest extends CodeInsightTestCase {
|
||||
}
|
||||
|
||||
public void testClassAndSecondary() throws Exception{
|
||||
doTest("classAndSecondary", new String[]{"pack1.Class1", "pack1.Class2"}, "pack2");
|
||||
try {
|
||||
doTest("classAndSecondary", new String[]{"pack1.Class1", "pack1.Class2"}, "pack2");
|
||||
fail("Conflicts expected");
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
assertEquals("A package-local class <b><code>Class2</code></b> will no longer be accessible from field <b><code>User.class2</code></b>", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void testIdeadev27996() throws Exception {
|
||||
|
||||
@@ -10,7 +10,6 @@ import com.intellij.psi.PsiModifier;
|
||||
import com.intellij.psi.search.ProjectScope;
|
||||
import com.intellij.refactoring.move.moveMembers.MockMoveMembersOptions;
|
||||
import com.intellij.refactoring.move.moveMembers.MoveMembersProcessor;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
@@ -95,7 +94,7 @@ public class MoveMembersTest extends MultiFileTestCase {
|
||||
fail("conflict expected");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertEquals(e.getMessage(), "Found conflicts: Field <b><code>B.ONE</code></b> has write access but is moved to an interface");
|
||||
assertEquals("Field <b><code>B.ONE</code></b> has write access but is moved to an interface", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,15 +138,7 @@ public class MoveMembersTest extends MultiFileTestCase {
|
||||
|
||||
MockMoveMembersOptions options = new MockMoveMembersOptions(targetClass.getQualifiedName(), memberSet);
|
||||
options.setMemberVisibility(null);
|
||||
new MoveMembersProcessor(myProject, null, options){
|
||||
@Override
|
||||
protected boolean showConflicts(MultiMap<PsiElement, String> conflicts) {
|
||||
if (!conflicts.isEmpty()) {
|
||||
throw new RuntimeException("Found conflicts: " + conflicts.values().iterator().next());
|
||||
}
|
||||
return super.showConflicts(conflicts);
|
||||
}
|
||||
}.run();
|
||||
new MoveMembersProcessor(myProject, null, options).run();
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ public class PushDownTest extends LightCodeInsightTestCase {
|
||||
if (failure ? conflicts.isEmpty() : !conflicts.isEmpty()) {
|
||||
fail(failure ? "Conflict was not detected" : "False conflict was detected");
|
||||
}
|
||||
return super.showConflicts(conflicts);
|
||||
return true;
|
||||
}
|
||||
}.run();
|
||||
|
||||
@@ -92,4 +92,4 @@ public class PushDownTest extends LightCodeInsightTestCase {
|
||||
public void testThisRefInAnonymous() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,11 +30,7 @@ public class RemoveMiddleManTest extends MultiFileTestCase{
|
||||
return "/refactoring/removemiddleman/";
|
||||
}
|
||||
|
||||
private void doTest() throws Exception {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
private void doTest(final boolean delete) throws Exception {
|
||||
private void doTest(final String conflict) throws Exception {
|
||||
doTest(new PerformAction() {
|
||||
public void performAction(final VirtualFile rootDir, final VirtualFile rootAfter) throws Exception {
|
||||
PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.allScope(getProject()));
|
||||
@@ -48,35 +44,42 @@ public class RemoveMiddleManTest extends MultiFileTestCase{
|
||||
for (PsiMethod method : methods) {
|
||||
final MemberInfo info = new MemberInfo(method);
|
||||
info.setChecked(true);
|
||||
info.setToAbstract(delete);
|
||||
info.setToAbstract(true);
|
||||
infos.add(info);
|
||||
}
|
||||
RemoveMiddlemanProcessor processor = new RemoveMiddlemanProcessor(field, infos);
|
||||
processor.run();
|
||||
LocalFileSystem.getInstance().refresh(false);
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
try {
|
||||
RemoveMiddlemanProcessor processor = new RemoveMiddlemanProcessor(field, infos);
|
||||
processor.run();
|
||||
LocalFileSystem.getInstance().refresh(false);
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
if (conflict != null) fail("Conflict expected");
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (conflict == null) throw e;
|
||||
assertEquals(conflict, e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testNoGetter() throws Exception {
|
||||
doTest();
|
||||
doTest((String)null);
|
||||
}
|
||||
|
||||
public void testSiblings() throws Exception {
|
||||
doTest();
|
||||
doTest("foo() will be deleted. Hierarchy will be broken");
|
||||
}
|
||||
|
||||
|
||||
public void testInterface() throws Exception {
|
||||
doTest();
|
||||
doTest("foo() will be deleted. Hierarchy will be broken");
|
||||
}
|
||||
|
||||
public void testPresentGetter() throws Exception {
|
||||
doTest();
|
||||
doTest("foo() will be deleted. Hierarchy will be broken");
|
||||
}
|
||||
|
||||
public void testInterfaceDelegation() throws Exception {
|
||||
doTest();
|
||||
doTest("foo() will be deleted. Hierarchy will be broken");
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.testFramework.LightCodeInsightTestCase;
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.util.VisibilityUtil;
|
||||
|
||||
/**
|
||||
* @author dsl
|
||||
@@ -36,7 +37,7 @@ public class ConvertToInstanceMethodTest extends LightCodeInsightTestCase {
|
||||
assertTrue("<caret> is not on method name", targetElement instanceof PsiMethod);
|
||||
PsiMethod method = (PsiMethod) targetElement;
|
||||
new ConvertToInstanceMethodProcessor(getProject(),
|
||||
method, method.getParameterList().getParameters()[targetParameter], null).run();
|
||||
method, method.getParameterList().getParameters()[targetParameter], VisibilityUtil.ESCALATE_VISIBILITY).run();
|
||||
checkResultByFile(filePath + ".after");
|
||||
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.EmptyRunnable;
|
||||
import com.intellij.openapi.util.Factory;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.wm.WindowManager;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -464,10 +465,14 @@ public abstract class BaseRefactoringProcessor {
|
||||
}
|
||||
|
||||
protected boolean showConflicts(final MultiMap<PsiElement,String> conflicts) {
|
||||
if (!conflicts.isEmpty() && myPrepareSuccessfulSwingThreadCallback != null) {
|
||||
if (!conflicts.isEmpty() && ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
throw new RuntimeException(StringUtil.join(conflicts.values(), "\n"));
|
||||
}
|
||||
|
||||
if (myPrepareSuccessfulSwingThreadCallback != null && !conflicts.isEmpty()) {
|
||||
final ConflictsDialog conflictsDialog = new ConflictsDialog(myProject, conflicts);
|
||||
conflictsDialog.show();
|
||||
if (!conflictsDialog.isOK()){
|
||||
if (!conflictsDialog.isOK()) {
|
||||
if (conflictsDialog.isShowConflicts()) prepareSuccessful();
|
||||
return false;
|
||||
}
|
||||
@@ -493,4 +498,4 @@ public abstract class BaseRefactoringProcessor {
|
||||
return myElementLanguage;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user