mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-01 17:03:12 +07:00
[Java. Code completion] IDEA-379114 Support extract method in the end of statement for command completion
GitOrigin-RevId: 977ef8cfcd6e26781cc3cf1271a76bae20cb286c
This commit is contained in:
committed by
intellij-monorepo-bot
parent
c4c2af73ac
commit
03be8d99b0
+19
@@ -1433,6 +1433,9 @@ class JavaCommandsCompletionTest : LightFixtureCompletionTestCase() {
|
||||
}
|
||||
}
|
||||
""")
|
||||
|
||||
val elements = myFixture.completeBasic()
|
||||
assertTrue(elements.any { element -> element.lookupString.contains("Extract method", ignoreCase = true) })
|
||||
}
|
||||
|
||||
fun testExtractMethodControlFlowIfElseStatement() {
|
||||
@@ -1447,6 +1450,22 @@ class JavaCommandsCompletionTest : LightFixtureCompletionTestCase() {
|
||||
}
|
||||
}
|
||||
""")
|
||||
|
||||
val elements = myFixture.completeBasic()
|
||||
assertTrue(elements.any { element -> element.lookupString.contains("Extract method", ignoreCase = true) })
|
||||
}
|
||||
|
||||
fun testExtractMethodInTheEndOfStatement() {
|
||||
Registry.get("ide.completion.command.force.enabled").setValue(true, getTestRootDisposable())
|
||||
myFixture.configureByText(JavaFileType.INSTANCE, """
|
||||
class A {
|
||||
void foo() {
|
||||
System.out.println(1).<caret>;
|
||||
}
|
||||
""")
|
||||
|
||||
val elements = myFixture.completeBasic()
|
||||
assertTrue(elements.any { element -> element.lookupString.contains("Extract method", ignoreCase = true) })
|
||||
}
|
||||
|
||||
fun testExtractMethodControlFlowIfElseIfStatement() {
|
||||
|
||||
+13
-3
@@ -115,9 +115,13 @@ abstract class AbstractExtractMethodCompletionCommandProvider(
|
||||
if (controlFlowStatement != null) {
|
||||
editor?.selectionModel?.setSelection(controlFlowStatement.textRange.startOffset, controlFlowStatement.textRange.endOffset)
|
||||
return super.isApplicable(offset, psiFile, editor)
|
||||
} else {
|
||||
return findOutermostExpression(offset, psiFile, editor) != null && super.isApplicable(offset, psiFile, editor)
|
||||
}
|
||||
val outermostExpression = findOutermostExpression(offset, psiFile, editor)
|
||||
if (outermostExpression != null) {
|
||||
editor?.selectionModel?.setSelection(outermostExpression.textRange.startOffset, outermostExpression.textRange.endOffset)
|
||||
return super.isApplicable(offset, psiFile, editor)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
override fun createCommand(context: CommandCompletionProviderContext): ActionCompletionCommand {
|
||||
@@ -133,8 +137,14 @@ abstract class AbstractExtractMethodCompletionCommandProvider(
|
||||
val controlFlowStatement = findControlFlowStatement(offset, psiFile)
|
||||
if (controlFlowStatement != null) {
|
||||
editor.selectionModel.setSelection(controlFlowStatement.textRange.startOffset, controlFlowStatement.textRange.endOffset)
|
||||
super.execute(offset, psiFile, editor)
|
||||
return
|
||||
}
|
||||
val expression = findOutermostExpression(offset, psiFile, editor)
|
||||
if (expression != null) {
|
||||
editor.selectionModel.setSelection(expression.textRange.startOffset, expression.textRange.endOffset)
|
||||
super.execute(offset, psiFile, editor)
|
||||
}
|
||||
super.execute(offset, psiFile, editor)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user