mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
introduce code block parameter: extract from code block
This commit is contained in:
+3
-1
@@ -1036,7 +1036,9 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase {
|
||||
text = start + refText + (suffix != null ? suffix : "") + end;
|
||||
}
|
||||
final PsiElementFactory factory = JavaPsiFacade.getInstance(project).getElementFactory();
|
||||
return parent instanceof PsiStatement || parent instanceof PsiCodeBlock ? factory.createStatementFromText(text, parent) : factory.createExpressionFromText(text, parent);
|
||||
return parent instanceof PsiStatement ? factory.createStatementFromText(text, parent) :
|
||||
parent instanceof PsiCodeBlock ? factory.createCodeBlockFromText(text, parent)
|
||||
: factory.createExpressionFromText(text, parent);
|
||||
}
|
||||
|
||||
private boolean parentStatementNotFound(final Project project, Editor editor) {
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ class Test {
|
||||
});
|
||||
}
|
||||
|
||||
void foo(int i, Consumer<Integer> anObject){
|
||||
void foo(int i, Consumer<Integer> anObject) {
|
||||
|
||||
anObject.accept(i);
|
||||
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
import java.util.function.Consumer;
|
||||
|
||||
class Test {
|
||||
void bar() {
|
||||
foo(1, new Consumer<Integer>() {
|
||||
public void accept(Integer i) {
|
||||
System.out.println(i);
|
||||
System.out.println(i);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void foo(int i, Consumer<Integer> anObject) {
|
||||
if (i > 0) {
|
||||
|
||||
anObject.accept(i);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -8,7 +8,7 @@ class Test {
|
||||
});
|
||||
}
|
||||
|
||||
void foo(Runnable anObject){
|
||||
void foo(Runnable anObject) {
|
||||
|
||||
anObject.run();
|
||||
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
class Test {
|
||||
void bar() {
|
||||
foo(1);
|
||||
}
|
||||
|
||||
void foo(int i) {
|
||||
if (i > 0) {
|
||||
<selection>
|
||||
System.out.println(i);
|
||||
System.out.println(i);
|
||||
</selection>
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,10 @@ public class IntroduceFunctionalParameterTest extends LightRefactoringTestCase
|
||||
doTest(null);
|
||||
}
|
||||
|
||||
public void testIntConsumerFromIfStatement() throws Exception {
|
||||
doTest(null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
|
||||
Reference in New Issue
Block a user