mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-166301 Idea autocompletes {@code n} as {@code {@code null}}
This commit is contained in:
+22
-8
@@ -196,14 +196,7 @@ public class JavaDocCompletionContributor extends CompletionContributor {
|
||||
|
||||
suggestLinkWrappingVariants(parameters, result.withPrefixMatcher(CompletionUtil.findJavaIdentifierPrefix(parameters)), position);
|
||||
|
||||
if (!result.getPrefixMatcher().getPrefix().isEmpty()) {
|
||||
for (String keyword : ContainerUtil.ar("null", "true", "false")) {
|
||||
String tagText = "{@code " + keyword + "}";
|
||||
result.addElement(LookupElementBuilder.create(keyword).withPresentableText(tagText).withInsertHandler(
|
||||
(context, item) -> context.getDocument().replaceString(context.getStartOffset(), context.getTailOffset(), tagText))
|
||||
);
|
||||
}
|
||||
}
|
||||
suggestCodeLiterals(result, position);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -211,6 +204,27 @@ public class JavaDocCompletionContributor extends CompletionContributor {
|
||||
super.fillCompletionVariants(parameters, result);
|
||||
}
|
||||
|
||||
private static void suggestCodeLiterals(@NotNull CompletionResultSet result, PsiElement position) {
|
||||
PsiElement parent = position.getParent();
|
||||
if (parent instanceof PsiInlineDocTag && !"code".equals(((PsiInlineDocTag)parent).getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!result.getPrefixMatcher().getPrefix().isEmpty()) {
|
||||
for (String keyword : ContainerUtil.ar("null", "true", "false")) {
|
||||
LookupElementBuilder element = LookupElementBuilder.create(keyword);
|
||||
result.addElement(parent instanceof PsiInlineDocTag ? element : wrapIntoCodeTag(element));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static LookupElementBuilder wrapIntoCodeTag(LookupElementBuilder element) {
|
||||
String tagText = "{@code " + element.getLookupString() + "}";
|
||||
return element.withPresentableText(tagText).withInsertHandler(
|
||||
(context, item) -> context.getDocument().replaceString(context.getStartOffset(), context.getTailOffset(), tagText));
|
||||
}
|
||||
|
||||
private void suggestLinkWrappingVariants(@NotNull CompletionParameters parameters,
|
||||
@NotNull CompletionResultSet result,
|
||||
PsiElement position) {
|
||||
|
||||
+6
@@ -665,6 +665,12 @@ class Foo {
|
||||
myFixture.checkResult "/** {@code null}<caret> */"
|
||||
}
|
||||
|
||||
void "test null inside code tag"() {
|
||||
myFixture.configureByText 'a.java', "/** {@code nul<caret>} */"
|
||||
myFixture.completeBasic()
|
||||
myFixture.checkResult "/** {@code null<caret>} */"
|
||||
}
|
||||
|
||||
void "test completing inside qualified name"() {
|
||||
myFixture.configureByText 'a.java', "/** @see java.io.<caret> */"
|
||||
myFixture.completeBasic()
|
||||
|
||||
Reference in New Issue
Block a user