java introduce variable: include expression ending with '}' in chooser (IDEA-253043)

GitOrigin-RevId: a347b48e648d03f63561a6534d26ac909f780281
This commit is contained in:
Anna Kozlova
2020-10-26 14:53:27 +00:00
committed by intellij-monorepo-bot
parent 4c57042e8f
commit 0e32179fc8
2 changed files with 8 additions and 2 deletions
@@ -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;
}
}
@@ -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<java.lang.String>"); }
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"); }