mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
inplace introduce: insert whitespace before template if needed (IDEA-87487)
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
class Test {
|
||||
int f(){
|
||||
return<caret>-1;
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
class Test {
|
||||
|
||||
private int anInt;
|
||||
|
||||
int f(){
|
||||
anInt = -1;
|
||||
return anInt;
|
||||
}
|
||||
}
|
||||
@@ -43,6 +43,15 @@ public class InplaceIntroduceFieldTest extends AbstractJavaInplaceIntroduceTest
|
||||
|
||||
public void testBeforeAssignment() throws Exception {
|
||||
|
||||
doTest(new Pass<AbstractInplaceIntroducer>() {
|
||||
@Override
|
||||
public void pass(AbstractInplaceIntroducer inplaceIntroduceFieldPopup) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testTemplateAdjustment() throws Exception {
|
||||
|
||||
doTest(new Pass<AbstractInplaceIntroducer>() {
|
||||
@Override
|
||||
public void pass(AbstractInplaceIntroducer inplaceIntroduceFieldPopup) {
|
||||
|
||||
+19
-1
@@ -21,6 +21,11 @@ import com.intellij.codeInsight.template.ExpressionContext;
|
||||
import com.intellij.codeInsight.template.TextResult;
|
||||
import com.intellij.codeInsight.template.impl.TemplateManagerImpl;
|
||||
import com.intellij.codeInsight.template.impl.TemplateState;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.lang.LanguageTokenSeparatorGenerators;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.command.impl.StartMarkAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.RangeMarker;
|
||||
@@ -68,7 +73,20 @@ public abstract class InplaceVariableIntroducer<E extends PsiElement> extends In
|
||||
super(editor, elementToRename, project);
|
||||
myTitle = title;
|
||||
myOccurrences = occurrences;
|
||||
myExpr = expr;
|
||||
if (expr != null) {
|
||||
final ASTNode node = expr.getNode();
|
||||
final ASTNode astNode = LanguageTokenSeparatorGenerators.INSTANCE.forLanguage(expr.getLanguage())
|
||||
.generateWhitespaceBetweenTokens(node.getTreePrev(), node);
|
||||
if (astNode != null) {
|
||||
new WriteCommandAction<Object>(project, "Normalize declaration") {
|
||||
@Override
|
||||
protected void run(Result<Object> result) throws Throwable {
|
||||
node.getTreeParent().addChild(astNode, node);
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
myExpr = expr;
|
||||
}
|
||||
myExprMarker = myExpr != null && myExpr.isPhysical() ? createMarker(myExpr) : null;
|
||||
initOccurrencesMarkers();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user