mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
extract functional parameter: ensure final inside anonymous, no additional qualifier (IDEA-138895)
This commit is contained in:
+2
-3
@@ -47,7 +47,6 @@ import com.intellij.openapi.util.*;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.wm.WindowManager;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.*;
|
||||
import com.intellij.psi.controlFlow.ControlFlowUtil;
|
||||
@@ -861,7 +860,7 @@ public class ExtractMethodProcessor implements MatchProvider {
|
||||
final PsiStatement exitStatementCopy = prepareMethodBody(newMethod, true);
|
||||
|
||||
if (myExpression == null) {
|
||||
if (myNeedChangeContext) {
|
||||
if (myNeedChangeContext && isNeedToChangeCallContext()) {
|
||||
for (PsiElement element : myElements) {
|
||||
ChangeContextUtil.encodeContextInfo(element, false);
|
||||
}
|
||||
@@ -1387,7 +1386,7 @@ public class ExtractMethodProcessor implements MatchProvider {
|
||||
else {
|
||||
skipInstanceQualifier = instanceQualifier == null || instanceQualifier instanceof PsiThisExpression;
|
||||
if (skipInstanceQualifier) {
|
||||
if (myNeedChangeContext) {
|
||||
if (isNeedToChangeCallContext() && myNeedChangeContext) {
|
||||
boolean needsThisQualifier = false;
|
||||
PsiElement parent = myCodeFragmentMember;
|
||||
while (!myTargetClass.equals(parent)) {
|
||||
|
||||
+9
@@ -437,6 +437,10 @@ public class IntroduceParameterHandler extends IntroduceHandlerBase {
|
||||
}
|
||||
|
||||
boolean mustBeFinal = false;
|
||||
if (myExpr != null) {
|
||||
final PsiElement parent = myExpr.getUserData(ElementToWorkOn.PARENT);
|
||||
mustBeFinal = parent != null && PsiTreeUtil.getParentOfType(parent, PsiClass.class, PsiMethod.class) != method;
|
||||
}
|
||||
for (PsiExpression occurrence : occurences) {
|
||||
if (PsiTreeUtil.getParentOfType(occurrence, PsiClass.class, PsiMethod.class) != method) {
|
||||
mustBeFinal = true;
|
||||
@@ -705,6 +709,11 @@ public class IntroduceParameterHandler extends IntroduceHandlerBase {
|
||||
return new MyAbstractExtractDialog();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isNeedToChangeCallContext() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setMethodName(String methodName) {
|
||||
myMethodName = methodName;
|
||||
}
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
class Test {
|
||||
void foo(final Runnable anObject) {
|
||||
Runnable c = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
anObject.run();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
class Test {
|
||||
void foo() {
|
||||
Runnable c = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
<selection>System.out.println();</selection>
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -57,6 +57,10 @@ public class IntroduceFunctionalParameterTest extends LightRefactoringTestCase
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testInsideAnonymous() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
|
||||
Reference in New Issue
Block a user