mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
extract method: pre/post expressions checks fixed (IDEA-65476 )
This commit is contained in:
+11
-4
@@ -51,6 +51,7 @@ import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.LocalSearchScope;
|
||||
import com.intellij.psi.search.SearchScope;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.PsiFormatUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
@@ -736,10 +737,16 @@ public class ExtractMethodProcessor implements MatchProvider {
|
||||
if (myExpression instanceof PsiAssignmentExpression) {
|
||||
expression2Replace = ((PsiAssignmentExpression)myExpression).getRExpression();
|
||||
} else if (myExpression instanceof PsiPostfixExpression || myExpression instanceof PsiPrefixExpression) {
|
||||
PsiExpression operand = myExpression instanceof PsiPostfixExpression ? ((PsiPostfixExpression)myExpression).getOperand() :
|
||||
((PsiPrefixExpression)myExpression).getOperand();
|
||||
expression2Replace =
|
||||
((PsiBinaryExpression)myExpression.replace(myElementFactory.createExpressionFromText(operand.getText() + " + x", operand))).getROperand();
|
||||
final IElementType elementType = myExpression instanceof PsiPostfixExpression
|
||||
? ((PsiPostfixExpression)myExpression).getOperationTokenType()
|
||||
: ((PsiPrefixExpression)myExpression).getOperationTokenType();
|
||||
if (elementType == JavaTokenType.PLUSPLUS || elementType == JavaTokenType.MINUSMINUS) {
|
||||
PsiExpression operand = myExpression instanceof PsiPostfixExpression ? ((PsiPostfixExpression)myExpression).getOperand() :
|
||||
((PsiPrefixExpression)myExpression).getOperand();
|
||||
expression2Replace =
|
||||
((PsiBinaryExpression)myExpression.replace(myElementFactory.createExpressionFromText(operand.getText() + " + x", operand))).getROperand();
|
||||
}
|
||||
|
||||
}
|
||||
myExpression = (PsiExpression)IntroduceVariableBase.replace(expression2Replace, myMethodCall, myProject);
|
||||
myMethodCall = PsiTreeUtil.getParentOfType(myExpression.findElementAt(myExpression.getText().indexOf(myMethodCall.getText())), PsiMethodCallExpression.class);
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
class Test {
|
||||
String[] foo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
boolean bar(String s) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void foooooo() {
|
||||
String[] modules = foo();
|
||||
int i = 0;
|
||||
while (i < modules.length && <selection>!bar(modules[i])</selection>) {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
class Test {
|
||||
String[] foo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
boolean bar(String s) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void foooooo() {
|
||||
String[] modules = foo();
|
||||
int i = 0;
|
||||
while (i < modules.length && newMethod(modules[i])) {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean newMethod(String module) {
|
||||
return !bar(module);
|
||||
}
|
||||
}
|
||||
@@ -479,6 +479,10 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testFoldInWhile() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doPrepareErrorTest(final String expectedMessage) throws Exception {
|
||||
String expectedError = null;
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user