mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
AIOOBE
This commit is contained in:
@@ -117,26 +117,28 @@ public class ExtractMethodUtil {
|
||||
final PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
|
||||
if (!manager.areElementsEquivalent(oldTarget, newTarget)) {
|
||||
final PsiParameter[] oldParameters = oldTarget.getParameterList().getParameters();
|
||||
final PsiMethodCallExpression copy = (PsiMethodCallExpression)call.copy();
|
||||
final PsiExpression[] args = copy.getArgumentList().getExpressions();
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
PsiExpression arg = args[i];
|
||||
PsiType paramType = i < oldParameters.length ? oldParameters[i].getType() : oldParameters[oldParameters.length - 1].getType();
|
||||
final PsiTypeCastExpression cast = (PsiTypeCastExpression)factory.createExpressionFromText("(a)b", null);
|
||||
final PsiTypeElement typeElement = cast.getCastType();
|
||||
assert typeElement != null;
|
||||
typeElement.replace(factory.createTypeElement(paramType));
|
||||
final PsiExpression operand = cast.getOperand();
|
||||
assert operand != null;
|
||||
operand.replace(arg);
|
||||
arg.replace(cast);
|
||||
}
|
||||
if (oldParameters.length > 0) {
|
||||
final PsiMethodCallExpression copy = (PsiMethodCallExpression)call.copy();
|
||||
final PsiExpression[] args = copy.getArgumentList().getExpressions();
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
PsiExpression arg = args[i];
|
||||
PsiType paramType = i < oldParameters.length ? oldParameters[i].getType() : oldParameters[oldParameters.length - 1].getType();
|
||||
final PsiTypeCastExpression cast = (PsiTypeCastExpression)factory.createExpressionFromText("(a)b", null);
|
||||
final PsiTypeElement typeElement = cast.getCastType();
|
||||
assert typeElement != null;
|
||||
typeElement.replace(factory.createTypeElement(paramType));
|
||||
final PsiExpression operand = cast.getOperand();
|
||||
assert operand != null;
|
||||
operand.replace(arg);
|
||||
arg.replace(cast);
|
||||
}
|
||||
|
||||
for (int i = 0; i < copy.getArgumentList().getExpressions().length; i++) {
|
||||
PsiExpression oldarg = call.getArgumentList().getExpressions()[i];
|
||||
PsiTypeCastExpression cast = (PsiTypeCastExpression)copy.getArgumentList().getExpressions()[i];
|
||||
if (!RedundantCastUtil.isCastRedundant(cast)) {
|
||||
oldarg.replace(cast);
|
||||
for (int i = 0; i < copy.getArgumentList().getExpressions().length; i++) {
|
||||
PsiExpression oldarg = call.getArgumentList().getExpressions()[i];
|
||||
PsiTypeCastExpression cast = (PsiTypeCastExpression)copy.getArgumentList().getExpressions()[i];
|
||||
if (!RedundantCastUtil.isCastRedundant(cast)) {
|
||||
oldarg.replace(cast);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
public class ExtractMethods {
|
||||
void newMethod() {
|
||||
int i = 0;
|
||||
<selection>if (true) {
|
||||
newMethod(i);
|
||||
}</selection>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
public class ExtractMethods {
|
||||
void newMethod() {
|
||||
int i = 0;
|
||||
newMethod(i);
|
||||
}
|
||||
|
||||
private void newMethod(int i) {
|
||||
if (true) {
|
||||
newMethod(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -420,6 +420,10 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testRecursiveCallToExtracted() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doPrepareErrorTest(final String expectedMessage) throws Exception {
|
||||
String expectedError = null;
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user