mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
extract method object: do not make static when already static (IDEA-98290)
This commit is contained in:
+2
-1
@@ -682,7 +682,8 @@ public class ExtractMethodObjectProcessor extends BaseRefactoringProcessor {
|
||||
@Override
|
||||
public PsiElement processMatch(final Match match) throws IncorrectOperationException {
|
||||
final boolean makeStatic = myInnerMethod != null &&
|
||||
RefactoringUtil.isInStaticContext(match.getMatchStart(), getExtractedMethod().getContainingClass());
|
||||
RefactoringUtil.isInStaticContext(match.getMatchStart(), getExtractedMethod().getContainingClass()) &&
|
||||
!myInnerMethod.getContainingClass().hasModifierProperty(PsiModifier.STATIC);
|
||||
final PsiElement element = super.processMatch(match);
|
||||
if (makeStatic) {
|
||||
myMadeStatic = true;
|
||||
|
||||
@@ -193,7 +193,7 @@ public class DuplicatesImpl {
|
||||
if (duplicates.size() == 1) {
|
||||
previewMatch(project, duplicates.get(0), editor);
|
||||
}
|
||||
final int answer = Messages.showYesNoDialog(project,
|
||||
final int answer = ApplicationManager.getApplication().isUnitTestMode() ? 0 : Messages.showYesNoDialog(project,
|
||||
RefactoringBundle.message("0.has.detected.1.code.fragments.in.this.file.that.can.be.replaced.with.a.call.to.extracted.method",
|
||||
ApplicationNamesInfo.getInstance().getProductName(), duplicates.size()),
|
||||
"Process Duplicates", Messages.getQuestionIcon());
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
class Bag {
|
||||
Integer x;
|
||||
Integer y;
|
||||
}
|
||||
|
||||
class Foo {
|
||||
public static void foo() {
|
||||
Bag b = new Bag();
|
||||
System.out.println(<selection>b</selection>.x);
|
||||
System.out.println(b.x);
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
class Bag {
|
||||
Integer x;
|
||||
Integer y;
|
||||
}
|
||||
|
||||
class Foo {
|
||||
public static void foo() {
|
||||
Bag b = new Bag();
|
||||
System.out.println(new Inner(b).invoke().x);
|
||||
System.out.println(new Inner(b).invoke().x);
|
||||
}
|
||||
|
||||
private static class Inner {
|
||||
private Bag b;
|
||||
|
||||
public Inner(Bag b) {
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public Bag invoke() {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
@@ -118,4 +118,8 @@ public class ExtractMethodObjectWithMultipleExitPointsTest extends LightRefactor
|
||||
public void testReturnExitStatement() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testFromStaticContext() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user