Adding {} in string template if necessary.
#KT-2637 in progress
This commit is contained in:
@@ -219,6 +219,12 @@ public class JetPsiFactory {
|
|||||||
return whenEntry;
|
return whenEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static JetStringTemplateEntryWithExpression createBlockStringTemplateEntry(@NotNull Project project, @NotNull JetExpression expression) {
|
||||||
|
JetStringTemplateExpression stringTemplateExpression = (JetStringTemplateExpression) createExpression(project,
|
||||||
|
"\"${" + expression.getText() + "}\"");
|
||||||
|
return (JetStringTemplateEntryWithExpression) stringTemplateExpression.getEntries()[0];
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static JetImportDirective createImportDirective(Project project, @NotNull String path) {
|
public static JetImportDirective createImportDirective(Project project, @NotNull String path) {
|
||||||
return createImportDirective(project, new ImportPath(path));
|
return createImportDirective(project, new ImportPath(path));
|
||||||
|
|||||||
@@ -19,10 +19,7 @@ import com.intellij.psi.search.searches.ReferencesSearch;
|
|||||||
import com.intellij.refactoring.HelpID;
|
import com.intellij.refactoring.HelpID;
|
||||||
import com.intellij.refactoring.RefactoringBundle;
|
import com.intellij.refactoring.RefactoringBundle;
|
||||||
import com.intellij.refactoring.util.RefactoringMessageDialog;
|
import com.intellij.refactoring.util.RefactoringMessageDialog;
|
||||||
import com.intellij.util.Processor;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import com.intellij.util.Query;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetProperty;
|
|
||||||
import org.jetbrains.jet.plugin.JetLanguage;
|
import org.jetbrains.jet.plugin.JetLanguage;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -43,7 +40,7 @@ public class KotlinInlineLocalHandler extends InlineActionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void inlineElement(Project project, Editor editor, PsiElement element) {
|
public void inlineElement(final Project project, Editor editor, PsiElement element) {
|
||||||
final JetProperty val = (JetProperty) element;
|
final JetProperty val = (JetProperty) element;
|
||||||
String name = val.getName();
|
String name = val.getName();
|
||||||
|
|
||||||
@@ -82,7 +79,14 @@ public class KotlinInlineLocalHandler extends InlineActionHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
for (PsiReference reference : references) {
|
for (PsiReference reference : references) {
|
||||||
reference.getElement().replace(initializer.copy());
|
PsiElement referenceElement = reference.getElement();
|
||||||
|
if (referenceElement.getParent() instanceof JetSimpleNameStringTemplateEntry &&
|
||||||
|
!(initializer instanceof JetSimpleNameExpression)) {
|
||||||
|
referenceElement.getParent().replace(JetPsiFactory.createBlockStringTemplateEntry(project, initializer));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
referenceElement.replace(initializer.copy());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val.delete();
|
val.delete();
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
fun f() {
|
||||||
|
val v = 150 + 150
|
||||||
|
println("value is $<caret>v")
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun f() {
|
||||||
|
println("value is ${150 + 150}")
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
fun f() {
|
||||||
|
val v = 150 + 150
|
||||||
|
println("value is ${<caret>v}")
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun f() {
|
||||||
|
println("value is ${150 + 150}")
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
fun f() {
|
||||||
|
val v = otherValue
|
||||||
|
println("value is $<caret>v")
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun f() {
|
||||||
|
println("value is $otherValue")
|
||||||
|
}
|
||||||
@@ -218,6 +218,21 @@ public class InlineTestGenerated extends AbstractInlineTest {
|
|||||||
doTest("idea/testData/refactoring/inline/addParenthesis/UnaryIntoBinary.kt");
|
doTest("idea/testData/refactoring/inline/addParenthesis/UnaryIntoBinary.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("StringTemplate.kt")
|
||||||
|
public void testStringTemplate() throws Exception {
|
||||||
|
doTest("idea/testData/refactoring/inline/addParenthesis/StringTemplate.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("StringTemplateAlreadyInBraces.kt")
|
||||||
|
public void testStringTemplateAlreadyInBraces() throws Exception {
|
||||||
|
doTest("idea/testData/refactoring/inline/addParenthesis/StringTemplateAlreadyInBraces.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("StringTemplateDontAdd.kt")
|
||||||
|
public void testStringTemplateDontAdd() throws Exception {
|
||||||
|
doTest("idea/testData/refactoring/inline/addParenthesis/StringTemplateDontAdd.kt");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Test suite() {
|
public static Test suite() {
|
||||||
|
|||||||
Reference in New Issue
Block a user