mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
IDEA-144461 AutoCompletion doesn't insert whitespace after annotation
This commit is contained in:
+11
-7
@@ -108,8 +108,15 @@ class JavaClassNameInsertHandler implements InsertHandler<JavaPsiClassReferenceE
|
||||
fillTypeArgs |= psiClass.hasTypeParameters() && PsiUtil.getLanguageLevel(file).isAtLeast(LanguageLevel.JDK_1_5);
|
||||
}
|
||||
}
|
||||
else if (insertingAnnotationWithParameters(context, item)) {
|
||||
JavaCompletionUtil.insertParentheses(context, item, false, true);
|
||||
else if (insertingAnnotation(context, item)) {
|
||||
if (shouldHaveAnnotationParameters(psiClass)) {
|
||||
JavaCompletionUtil.insertParentheses(context, item, false, true);
|
||||
}
|
||||
CharSequence text = context.getDocument().getCharsSequence();
|
||||
int tail = context.getTailOffset();
|
||||
if (text.length() > tail && Character.isLetter(text.charAt(tail))) {
|
||||
context.getDocument().insertString(tail, " ");
|
||||
}
|
||||
}
|
||||
|
||||
if (fillTypeArgs && context.getCompletionChar() != '(') {
|
||||
@@ -164,15 +171,12 @@ class JavaClassNameInsertHandler implements InsertHandler<JavaPsiClassReferenceE
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean insertingAnnotationWithParameters(InsertionContext context, LookupElement item) {
|
||||
private static boolean insertingAnnotation(InsertionContext context, LookupElement item) {
|
||||
final Object obj = item.getObject();
|
||||
if (!(obj instanceof PsiClass) || !((PsiClass)obj).isAnnotationType()) return false;
|
||||
|
||||
PsiElement leaf = context.getFile().findElementAt(context.getStartOffset());
|
||||
if (psiElement(PsiIdentifier.class).withParents(PsiJavaCodeReferenceElement.class, PsiAnnotation.class).accepts(leaf)) {
|
||||
return shouldHaveAnnotationParameters((PsiClass)obj);
|
||||
}
|
||||
return false;
|
||||
return psiElement(PsiIdentifier.class).withParents(PsiJavaCodeReferenceElement.class, PsiAnnotation.class).accepts(leaf);
|
||||
}
|
||||
|
||||
static boolean shouldHaveAnnotationParameters(PsiClass annoClass) {
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
@interface AbcdAnno {}
|
||||
|
||||
class Foo {
|
||||
void foo(@Abc<caret>Foo f) {}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
@interface AbcdAnno {}
|
||||
|
||||
class Foo {
|
||||
void foo(@AbcdAnno<caret> Foo f) {}
|
||||
}
|
||||
+1
@@ -1005,6 +1005,7 @@ public class ListUtils {
|
||||
|
||||
public void testOnlyAnnotationsAfterAt() throws Throwable { doTest() }
|
||||
public void testOnlyAnnotationsAfterAt2() throws Throwable { doTest('\n') }
|
||||
public void testAnnotationBeforeIdentifier() { doTest('\n') }
|
||||
|
||||
public void testOnlyExceptionsInCatch1() throws Exception { doTest('\n') }
|
||||
public void testOnlyExceptionsInCatch2() throws Exception { doTest('\n') }
|
||||
|
||||
Reference in New Issue
Block a user