don't add annotation attribute braces when typing comma inside string (IDEA-177182)

This commit is contained in:
peter
2017-08-09 18:39:04 +02:00
parent 3d1ba95725
commit 45f9ede9ac
4 changed files with 11 additions and 1 deletions

View File

@@ -194,7 +194,7 @@ public class JavaTypedHandler extends TypedHandlerDelegate {
int caret = editor.getCaretModel().getOffset();
if (mightBeInsideDefaultAnnotationAttribute(editor, caret - 2)) {
PsiDocumentManager.getInstance(project).commitAllDocuments();
PsiAnnotation anno = PsiTreeUtil.findElementOfClassAtOffset(file, caret, PsiAnnotation.class, false);
PsiAnnotation anno = PsiTreeUtil.getParentOfType(file.findElementAt(caret), PsiAnnotation.class, false, PsiExpression.class, PsiComment.class);
PsiNameValuePair attr = anno == null ? null : getTheOnlyDefaultAttribute(anno);
if (attr != null && hasDefaultArrayMethod(anno) && !(attr.getValue() instanceof PsiArrayInitializerMemberValue)) {
editor.getDocument().insertString(caret, "}");

View File

@@ -0,0 +1,4 @@
public @interface Category {
String[] value();
}
@Category("foo,<caret>")

View File

@@ -0,0 +1,4 @@
public @interface Category {
String[] value();
}
@Category("foo<caret>")

View File

@@ -114,6 +114,8 @@ public class JavaTypingTest extends LightPlatformCodeInsightFixtureTestCase {
doTest(',');
}
public void testCommaInDefaultAnnotationStringArgumentWhenArrayIsExpected() { doTest(','); }
private void doTest(char c) {
myFixture.configureByFile(getTestName(true) + "_before.java");
myFixture.type(c);