KT-3575, KT-2297 Inserting pair for "${": use JetPairMatcher instead of KotlinTypeHandler

#KT-3575 fixed
This commit is contained in:
Sergey Rostov
2013-05-20 17:02:38 +04:00
parent b2bb581127
commit 76edecb90a
3 changed files with 8 additions and 15 deletions
@@ -39,7 +39,8 @@ public class JetPairMatcher implements PairedBraceMatcher {
@Override
public boolean isPairedBracesAllowedBeforeType(@NotNull IElementType lbraceType, @Nullable IElementType contextType) {
return JetTokens.WHITE_SPACE_OR_COMMENT_BIT_SET.contains(contextType)
return lbraceType.equals(JetTokens.LONG_TEMPLATE_ENTRY_START)
|| JetTokens.WHITE_SPACE_OR_COMMENT_BIT_SET.contains(contextType)
|| contextType == JetTokens.SEMICOLON
|| contextType == JetTokens.COMMA
|| contextType == JetTokens.RPAR
@@ -57,20 +57,6 @@ public class KotlinTypedHandler extends TypedHandlerDelegate {
JetLtGtTypingUtils.handleJetAutoCloseLT(editor);
return Result.STOP;
}
if (!(file instanceof JetFile) || !CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET) {
return Result.CONTINUE;
}
if (c == '{') {
PsiDocumentManager.getInstance(project).commitAllDocuments();
int offset = editor.getCaretModel().getOffset();
PsiElement previousElement = file.findElementAt(offset - 1);
if (previousElement instanceof LeafPsiElement
&& ((LeafPsiElement) previousElement).getElementType() == JetTokens.LONG_TEMPLATE_ENTRY_START) {
editor.getDocument().insertString(offset, "}");
}
return Result.STOP;
}
return Result.CONTINUE;
}
}
@@ -26,6 +26,12 @@ public class TypedHandlerTest extends LightCodeInsightTestCase {
checkResultByText("val x = \"${}\"");
}
public void testKT3575() throws Exception {
configureFromFileText("a.kt", "val x = \"$<caret>]\"");
EditorTestUtil.performTypingAction(getEditor(), '{');
checkResultByText("val x = \"${}]\"");
}
public void testTypeLtInFunDeclaration() throws Exception {
doLtGtTest("fun <caret>");
}