mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
ExtractToMethodReferenceIntention: fix for anonymous class argument
This commit is contained in:
+2
-1
@@ -28,6 +28,7 @@ import com.intellij.refactoring.util.duplicates.MethodDuplicatesHandler;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.text.UniqueNameGenerator;
|
||||
import com.siyeh.IntentionPowerPackBundle;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import com.siyeh.ig.psiutils.CommentTracker;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -93,7 +94,7 @@ public class ExtractToMethodReferenceIntention extends BaseElementAtCaretIntenti
|
||||
if (lambdaExpression != null) {
|
||||
PsiCodeBlock body = RefactoringUtil.expandExpressionLambdaToCodeBlock(lambdaExpression);
|
||||
|
||||
PsiClass targetClass = PsiTreeUtil.getParentOfType(lambdaExpression, PsiClass.class);
|
||||
PsiClass targetClass = ClassUtils.getContainingClass(lambdaExpression);
|
||||
if (targetClass == null) return;
|
||||
PsiElement[] elements = body.getStatements();
|
||||
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
class AnonymousClassArgument {
|
||||
{
|
||||
Thread t = new Thread(() <caret>-> {}) {} ;
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
class AnonymousClassArgument {
|
||||
{
|
||||
Thread t = new Thread(AnonymousClassArgument::<caret>run) {} ;
|
||||
}
|
||||
|
||||
private static void run() {
|
||||
}
|
||||
}
|
||||
+4
@@ -58,6 +58,10 @@ public class ExtractToMethodReferenceTest extends IPPTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testAnonymousClassArgument() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testUsedLocalVariables() {
|
||||
assertIntentionNotAvailable();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user