mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
introduce variable: enable inplace mode for non-physical subexpressions (IDEA-210792)
GitOrigin-RevId: 378a1bb760cae47fe7641c2afb7d9215f76bd5cb
This commit is contained in:
committed by
intellij-monorepo-bot
parent
abb658fd21
commit
7e751931e1
@@ -117,7 +117,7 @@ public class JavaRefactoringSupportProvider extends RefactoringSupportProvider {
|
||||
@Override
|
||||
public boolean isInplaceIntroduceAvailable(@NotNull PsiElement element, PsiElement context) {
|
||||
if (!(element instanceof PsiExpression)) return false;
|
||||
if (context == null || context.getContainingFile() != element.getContainingFile()) return false;
|
||||
if (context == null) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class C {
|
||||
{
|
||||
String s = "b<selection>a</selection>c";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
class C {
|
||||
{
|
||||
String a = "a";
|
||||
String s = "b" + a + "c";
|
||||
}
|
||||
}
|
||||
+9
@@ -6,6 +6,7 @@ import com.intellij.codeInsight.template.impl.TemplateState;
|
||||
import com.intellij.lang.injection.InjectedLanguageManager;
|
||||
import com.intellij.openapi.actionSystem.IdeActions;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.SelectionModel;
|
||||
import com.intellij.openapi.editor.actionSystem.EditorActionManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -28,6 +29,10 @@ public class InplaceIntroduceVariableTest extends AbstractJavaInplaceIntroduceTe
|
||||
@Nullable
|
||||
@Override
|
||||
protected PsiExpression getExpressionFromEditor() {
|
||||
SelectionModel selectionModel = getEditor().getSelectionModel();
|
||||
if (selectionModel.hasSelection()) {
|
||||
return IntroduceVariableBase.getSelectedExpression(getProject(), getFile(), selectionModel.getSelectionStart(), selectionModel.getSelectionEnd());
|
||||
}
|
||||
final PsiExpression expression = super.getExpressionFromEditor();
|
||||
if (expression != null) {
|
||||
return expression;
|
||||
@@ -45,6 +50,10 @@ public class InplaceIntroduceVariableTest extends AbstractJavaInplaceIntroduceTe
|
||||
doTest(introducer -> type("expr"));
|
||||
}
|
||||
|
||||
public void testFromSelection() {
|
||||
doTest(introducer -> type("a"));
|
||||
}
|
||||
|
||||
public void testConflictingInnerClassName() {
|
||||
final JavaCodeStyleSettings settings = JavaCodeStyleSettings.getInstance(getProject());
|
||||
settings.INSERT_INNER_CLASS_IMPORTS = true;
|
||||
|
||||
Reference in New Issue
Block a user