From 0e32179fc84fa3e7a455dee6dedf250601ce1602 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Mon, 26 Oct 2020 12:29:59 +0100 Subject: [PATCH] java introduce variable: include expression ending with '}' in chooser (IDEA-253043) GitOrigin-RevId: a347b48e648d03f63561a6534d26ac909f780281 --- .../introduceVariable/IntroduceVariableBase.java | 2 +- .../intellij/java/refactoring/IntroduceVariableTest.java | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java b/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java index 4472a4f1f7f4..96239d13b60e 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java @@ -287,7 +287,7 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase { if (text.charAt(correctedOffset) == ';') {//initially caret on the end of line correctedOffset--; } - if (correctedOffset < 0 || text.charAt(correctedOffset) != ')' && text.charAt(correctedOffset) != '.') { + if (correctedOffset < 0 || text.charAt(correctedOffset) != ')' && text.charAt(correctedOffset) != '.' && text.charAt(correctedOffset) != '}') { correctedOffset = offset; } } diff --git a/java/java-tests/testSrc/com/intellij/java/refactoring/IntroduceVariableTest.java b/java/java-tests/testSrc/com/intellij/java/refactoring/IntroduceVariableTest.java index a4ac42b10655..68fc8219779c 100644 --- a/java/java-tests/testSrc/com/intellij/java/refactoring/IntroduceVariableTest.java +++ b/java/java-tests/testSrc/com/intellij/java/refactoring/IntroduceVariableTest.java @@ -4,6 +4,7 @@ package com.intellij.java.refactoring; import com.intellij.JavaTestUtil; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.CommonClassNames; import com.intellij.psi.PsiElement; @@ -17,6 +18,8 @@ import com.intellij.refactoring.introduceVariable.IntroduceVariableHandler; import com.intellij.refactoring.introduceVariable.IntroduceVariableSettings; import com.intellij.refactoring.ui.TypeSelectorManagerImpl; import com.intellij.testFramework.LightJavaCodeInsightTestCase; +import com.intellij.ui.ChooserInterceptor; +import com.intellij.ui.UiInterceptors; import com.intellij.util.containers.MultiMap; import org.jetbrains.annotations.NotNull; @@ -55,7 +58,10 @@ public class IntroduceVariableTest extends LightJavaCodeInsightTestCase { public void testFunctionalExpressionInSwitch() { doTest("p", true, true, true, "java.util.function.Predicate"); } public void testParenthesizedOccurrence1() { doTest("empty", true, true, true, "boolean"); } public void testParenthesizedOccurrence2() { doTest("s", true, true, true, JAVA_LANG_STRING); } - public void testAfterSemicolon() { doTest("s", true, true, true, CommonClassNames.JAVA_LANG_RUNNABLE); } + public void testAfterSemicolon() { + UiInterceptors.register(new ChooserInterceptor(null, StringUtil.escapeToRegexp("new Runnable() {...}"))); + doTest("s", true, true, true, CommonClassNames.JAVA_LANG_RUNNABLE); + } public void testConflictingField() { doTest("name", true, false, true, JAVA_LANG_STRING); } public void testConflictingFieldInExpression() { doTest("name", false, false, true, "int"); } public void testStaticConflictingField() { doTest("name", false, false, true, "int"); }