mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 13:31:28 +07:00
IDEA-118988 completion could add 'value=' in annotation
This commit is contained in:
@@ -465,8 +465,10 @@ public class JavaCompletionContributor extends CompletionContributor {
|
||||
if (!(method instanceof PsiAnnotationMethod)) continue;
|
||||
|
||||
final String attrName = method.getName();
|
||||
for (PsiNameValuePair apair : existingPairs) {
|
||||
if (Comparing.equal(apair.getName(), attrName)) continue methods;
|
||||
for (PsiNameValuePair existingAttr : existingPairs) {
|
||||
if (PsiTreeUtil.isAncestor(existingAttr, insertedElement, false)) break;
|
||||
if (Comparing.equal(existingAttr.getName(), attrName) ||
|
||||
PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME.equals(attrName) && existingAttr.getName() == null) continue methods;
|
||||
}
|
||||
LookupElementBuilder element = LookupElementBuilder.createWithIcon(method).withInsertHandler(new InsertHandler<LookupElement>() {
|
||||
@Override
|
||||
@@ -474,6 +476,15 @@ public class JavaCompletionContributor extends CompletionContributor {
|
||||
final Editor editor = context.getEditor();
|
||||
TailType.EQ.processTail(editor, editor.getCaretModel().getOffset());
|
||||
context.setAddCompletionChar(false);
|
||||
|
||||
context.commitDocument();
|
||||
PsiAnnotationParameterList paramList =
|
||||
PsiTreeUtil.findElementOfClassAtOffset(context.getFile(), context.getStartOffset(), PsiAnnotationParameterList.class, false);
|
||||
if (paramList != null && paramList.getAttributes().length > 0 && paramList.getAttributes()[0].getName() == null) {
|
||||
int valueOffset = paramList.getAttributes()[0].getTextRange().getStartOffset();
|
||||
context.getDocument().insertString(valueOffset, PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME);
|
||||
TailType.EQ.processTail(editor, valueOffset + PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME.length());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
@interface Anno {
|
||||
String value();
|
||||
String bar();
|
||||
String goo();
|
||||
}
|
||||
|
||||
@Anno("a", <caret>)
|
||||
class Foo {}
|
||||
@@ -0,0 +1,8 @@
|
||||
@interface Anno {
|
||||
String value();
|
||||
String bar();
|
||||
String goo();
|
||||
}
|
||||
|
||||
@Anno(value = "a", bar = <caret>)
|
||||
class Foo {}
|
||||
@@ -756,6 +756,13 @@ public class ListUtils {
|
||||
assertStringItems("bar", "foo");
|
||||
}
|
||||
|
||||
public void testAddExplicitValueInAnnotation() throws Throwable {
|
||||
configureByTestName()
|
||||
assertStringItems("bar", "goo")
|
||||
selectItem(myItems[0])
|
||||
checkResult()
|
||||
}
|
||||
|
||||
public void testUnnecessaryMethodMerging() throws Throwable {
|
||||
configureByFile(getTestName(false) + ".java");
|
||||
assertStringItems("fofoo", "fofoo");
|
||||
|
||||
Reference in New Issue
Block a user