mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-212024 Replace adjacent literal with selected completion option when pressing Tab
GitOrigin-RevId: bc5edd0fb01781ff6b6afab151550bdbf152c6c6
This commit is contained in:
committed by
intellij-monorepo-bot
parent
06f9df8be6
commit
018a02d757
@@ -24,6 +24,7 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.patterns.*;
|
||||
@@ -807,6 +808,15 @@ public class JavaCompletionContributor extends CompletionContributor {
|
||||
if (dummyIdentifier != null) {
|
||||
context.setDummyIdentifier(dummyIdentifier);
|
||||
}
|
||||
|
||||
PsiLiteralExpression literal =
|
||||
PsiTreeUtil.findElementOfClassAtOffset(file, context.getStartOffset(), PsiLiteralExpression.class, false);
|
||||
if (literal != null) {
|
||||
TextRange range = literal.getTextRange();
|
||||
if (range.getStartOffset() == context.getStartOffset()) {
|
||||
context.setReplacementOffset(range.getEndOffset());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
class MyClass {
|
||||
{
|
||||
String s = t<caret>"literal";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class MyClass {
|
||||
{
|
||||
String s = toString()<caret>;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+13
-4
@@ -30,8 +30,8 @@ public class TabCompletionTest extends LightFixtureCompletionTestCase {
|
||||
}
|
||||
|
||||
public void testReplaceThisWithSuper() {
|
||||
configureByFile("ReplaceThisWithSuper.java");
|
||||
checkResultByFile("ReplaceThisWithSuper_After.java");
|
||||
configureByTestName();
|
||||
checkResultJava();
|
||||
}
|
||||
|
||||
public void testTabInXml() {
|
||||
@@ -48,14 +48,23 @@ public class TabCompletionTest extends LightFixtureCompletionTestCase {
|
||||
myFixture.configureByFile("MethodCallBeforeAnnotation.java");
|
||||
myFixture.completeBasic();
|
||||
myFixture.type("tos\t");
|
||||
checkResultByFile("MethodCallBeforeAnnotation_After.java");
|
||||
checkResultJava();
|
||||
}
|
||||
|
||||
public void testMethodCallBeforeAnnotation2() {
|
||||
myFixture.configureByFile("MethodCallBeforeAnnotation2.java");
|
||||
myFixture.completeBasic();
|
||||
myFixture.type("tos\t");
|
||||
checkResultByFile("MethodCallBeforeAnnotation2_After.java");
|
||||
checkResultJava();
|
||||
}
|
||||
|
||||
public void testReplaceStringLiteral() {
|
||||
configureByTestName();
|
||||
checkResultJava();
|
||||
}
|
||||
|
||||
private void checkResultJava() {
|
||||
checkResultByFile(getTestName(false) + "_After.java");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user