mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
extract class: don't expand postfix expressions when no getter/setters were generated (IDEA-144369)
This commit is contained in:
+6
-8
@@ -63,14 +63,12 @@ public class ReplaceInstanceVariableIncrementDecrement extends FixableUsageInfo
|
||||
final PsiElement qualifier = lhs.getQualifier();
|
||||
final String operator = sign.getText();
|
||||
final String newExpression;
|
||||
final String strippedOperator = getStrippedOperator(operator);
|
||||
if (qualifier != null) {
|
||||
final String qualifierText = qualifier.getText();
|
||||
newExpression = qualifierText + '.' + delegateName + '.' +
|
||||
callSetter(qualifierText + '.' + delegateName + '.' + callGetter() + strippedOperator + "1");
|
||||
}
|
||||
else {
|
||||
newExpression = delegateName + '.' + callSetter(delegateName + '.' + callGetter() + strippedOperator + "1");
|
||||
if (getterName == null && setterName == null) {
|
||||
newExpression = (qualifier != null ? qualifier.getText() + "." : "") + delegateName + "." + fieldName + operator;
|
||||
} else {
|
||||
final String strippedOperator = getStrippedOperator(operator);
|
||||
newExpression = (qualifier != null ? qualifier.getText() + "." : "") + delegateName +
|
||||
'.' + callSetter(delegateName + '.' + callGetter() + strippedOperator + "1");
|
||||
}
|
||||
MutationUtils.replaceExpression(newExpression, reference);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
public class Extracted {
|
||||
public int myT = 7;
|
||||
|
||||
public Extracted() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class Test {
|
||||
public final Extracted extracted = new Extracted();
|
||||
|
||||
void foo() {
|
||||
if (extracted.myT++ == 7){}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
class Test {
|
||||
public int myT = 7;
|
||||
void foo() {
|
||||
if (myT++ == 7){}
|
||||
}
|
||||
}
|
||||
@@ -90,6 +90,16 @@ public class ExtractClassTest extends MultiFileTestCase{
|
||||
public void testFieldReference() throws Exception {
|
||||
doTestMethod("foo", "Field 'myField' needs getter");
|
||||
}
|
||||
|
||||
public void testIncrement() throws Exception {
|
||||
try {
|
||||
BaseRefactoringProcessor.ConflictsInTestsException.setTestIgnore(true);
|
||||
doTestField(null, false);
|
||||
}
|
||||
finally {
|
||||
BaseRefactoringProcessor.ConflictsInTestsException.setTestIgnore(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void testVarargs() throws Exception {
|
||||
doTestMethod();
|
||||
|
||||
@@ -599,7 +599,8 @@ public abstract class BaseRefactoringProcessor implements Runnable {
|
||||
|
||||
protected boolean showConflicts(@NotNull MultiMap<PsiElement, String> conflicts, @Nullable final UsageInfo[] usages) {
|
||||
if (!conflicts.isEmpty() && ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
throw new ConflictsInTestsException(conflicts.values());
|
||||
if (!ConflictsInTestsException.isTestIgnore()) throw new ConflictsInTestsException(conflicts.values());
|
||||
return true;
|
||||
}
|
||||
|
||||
if (myPrepareSuccessfulSwingThreadCallback != null && !conflicts.isEmpty()) {
|
||||
|
||||
Reference in New Issue
Block a user