mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
extract method: do not declare variables after call with local class defined in extracted method (IDEA-46775)
This commit is contained in:
@@ -419,6 +419,13 @@ public class ExtractMethodProcessor implements MatchProvider {
|
||||
if (!remainingReferences.isEmpty()) {
|
||||
throw new PrepareFailedException("Cannot extract method because the selected code fragment defines local classes used outside of the fragment", remainingReferences.get(0));
|
||||
}
|
||||
if (classExtracted) {
|
||||
for (PsiVariable variable : myControlFlowWrapper.getUsedVariables()) {
|
||||
if (isDeclaredInside(variable) && !variable.equals(myOutputVariable) && PsiUtil.resolveClassInType(variable.getType()) == localClass) {
|
||||
throw new PrepareFailedException("Cannot extract method because the selected code fragment defines variable of local class type used outside of the fragment", variable);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
class Test {
|
||||
void foo() {
|
||||
<selection>class X {}
|
||||
X x;
|
||||
</selection>
|
||||
x = null;
|
||||
}
|
||||
}
|
||||
@@ -338,6 +338,10 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testLocalClassDefinedInMethodWhichIsUsedLater() throws Exception {
|
||||
doPrepareErrorTest("Cannot extract method because the selected code fragment defines variable of local class type used outside of the fragment");
|
||||
}
|
||||
|
||||
public void testForceBraces() throws Exception {
|
||||
final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
|
||||
int old = settings.IF_BRACE_FORCE;
|
||||
|
||||
Reference in New Issue
Block a user