mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
EA-232230: extract method: choose correct anchor inside of field group
GitOrigin-RevId: dfcb53fe75f0f0bc4dd73e2167c5f07a321f095b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
c2e584b074
commit
68603732dc
+2
-10
@@ -10,6 +10,7 @@ import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.psi.*
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleManager
|
||||
import com.intellij.psi.formatter.java.MultipleFieldDeclarationHelper
|
||||
import com.intellij.psi.impl.source.DummyHolder
|
||||
import com.intellij.psi.impl.source.codeStyle.JavaCodeStyleManagerImpl
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
@@ -60,21 +61,12 @@ object ExtractMethodHelper {
|
||||
|
||||
fun normalizedAnchor(anchor: PsiMember): PsiMember {
|
||||
return if (anchor is PsiField) {
|
||||
findLastFieldInDeclaration(anchor)
|
||||
MultipleFieldDeclarationHelper.findLastFieldInGroup(anchor.node).psi as? PsiField ?: anchor
|
||||
} else {
|
||||
anchor
|
||||
}
|
||||
}
|
||||
|
||||
private fun findLastFieldInDeclaration(field: PsiField): PsiField {
|
||||
val nextSibling = PsiTreeUtil.skipWhitespacesForward(field)
|
||||
return if (PsiUtil.getElementType(nextSibling) == JavaTokenType.COMMA) {
|
||||
PsiTreeUtil.skipWhitespacesForward(nextSibling) as PsiField
|
||||
} else {
|
||||
field
|
||||
}
|
||||
}
|
||||
|
||||
fun addNullabilityAnnotation(owner: PsiModifierListOwner, nullability: Nullability) {
|
||||
val nullabilityManager = NullableNotNullManager.getInstance(owner.project)
|
||||
val annotation = when (nullability) {
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
public class Test {
|
||||
int x = <selection>2 + 2</selection>, y, /*comment*/ z = 0;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
public class Test {
|
||||
int x = newMethod(), y, /*comment*/ z = 0;
|
||||
|
||||
private int newMethod() {
|
||||
return 2 + 2;
|
||||
}
|
||||
}
|
||||
@@ -213,6 +213,10 @@ public class ExtractMethodNewTest extends LightJavaCodeInsightTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testFieldGroupAnchor() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testSCR27887() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user