mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
CodeBlockSurrounder: support multiple fields declaration
GitOrigin-RevId: 94421e98c10352732ba48e2df8994f9c09a7dcc3
This commit is contained in:
committed by
intellij-monorepo-bot
parent
dc20a6ca95
commit
d1c5022097
@@ -0,0 +1,11 @@
|
||||
class Test {
|
||||
int x = 2 + 2;
|
||||
int y;
|
||||
|
||||
{
|
||||
int temp = 3 + 3;
|
||||
y = temp;
|
||||
}
|
||||
|
||||
int z = 4 + 4;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
class Test {
|
||||
int x = 2 + 2, y = <selection>3 + 3</selection>, z = 4 + 4;
|
||||
}
|
||||
@@ -149,6 +149,7 @@ public class IntroduceVariableTest extends LightJavaCodeInsightTestCase {
|
||||
public void testReturnOrAndChain() { doTest("temp", true, false, false, JAVA_LANG_STRING); }
|
||||
public void testReturnTernary() { doTest("temp", true, false, false, JAVA_LANG_STRING); }
|
||||
public void testFieldInitializer() { doTest("temp", true, false, false, JAVA_LANG_STRING); }
|
||||
public void testFieldInitializerDenormalized() { doTest("temp", true, false, false, "int"); }
|
||||
public void testAssignTernary() { doTest("temp", true, false, false, JAVA_LANG_STRING); }
|
||||
public void testEnsureCodeBlockAroundBreakStatement() { doTest("temp", true, false, false, JAVA_LANG_STRING); }
|
||||
public void testEnsureCodeBlockForThrows() { doTest("temp", true, false, false, JAVA_LANG_STRING); }
|
||||
|
||||
@@ -242,11 +242,6 @@ public abstract class CodeBlockSurrounder {
|
||||
return null;
|
||||
}
|
||||
if (parent instanceof PsiField) {
|
||||
PsiElement prev = PsiTreeUtil.skipWhitespacesAndCommentsBackward(parent);
|
||||
PsiElement next = PsiTreeUtil.skipWhitespacesAndCommentsForward(parent);
|
||||
boolean multipleFieldsDeclaration = prev instanceof PsiJavaToken && ((PsiJavaToken)prev).getTokenType() == JavaTokenType.COMMA ||
|
||||
next instanceof PsiJavaToken && ((PsiJavaToken)next).getTokenType() == JavaTokenType.COMMA;
|
||||
if (multipleFieldsDeclaration) return null;
|
||||
return new ExtractFieldInitializerSurrounder(expression, (PsiField)parent);
|
||||
}
|
||||
|
||||
@@ -387,6 +382,7 @@ public abstract class CodeBlockSurrounder {
|
||||
|
||||
@Override
|
||||
@NotNull PsiStatement replace(@NotNull Project project, @NotNull PsiElementFactory factory) {
|
||||
myField.normalizeDeclaration();
|
||||
PsiClassInitializer initializer =
|
||||
ObjectUtils.tryCast(PsiTreeUtil.skipWhitespacesAndCommentsForward(myField), PsiClassInitializer.class);
|
||||
boolean isStatic = myField.hasModifierProperty(PsiModifier.STATIC);
|
||||
|
||||
Reference in New Issue
Block a user