mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-196864 Completion: classes containing no annotations are suggested after @
GitOrigin-RevId: aaa88b250510f5fb0f7c95bd2c8005a5546d53c0
This commit is contained in:
committed by
intellij-monorepo-bot
parent
a98c29b767
commit
88e5b6766e
+1
-1
@@ -82,7 +82,7 @@ public class JavaClassNameCompletionContributor extends CompletionContributor {
|
||||
@NotNull final Consumer<? super LookupElement> consumer) {
|
||||
final PsiElement insertedElement = parameters.getPosition();
|
||||
|
||||
if (JavaCompletionContributor.ANNOTATION_NAME.accepts(insertedElement)) {
|
||||
if (JavaCompletionContributor.getAnnotationNameIfInside(insertedElement) != null) {
|
||||
MultiMap<String, PsiClass> annoMap = getAllAnnotationClasses(insertedElement, matcher);
|
||||
Processor<PsiClass> processor = new LimitedAccessibleClassPreprocessor(parameters, filterByScope, anno -> {
|
||||
JavaPsiClassReferenceElement item = AllClassesGetter.createLookupItem(anno, JAVA_CLASS_INSERT_HANDLER);
|
||||
|
||||
+16
-7
@@ -65,9 +65,6 @@ import static com.intellij.util.ObjectUtils.assertNotNull;
|
||||
public class JavaCompletionContributor extends CompletionContributor {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.completion.JavaCompletionContributor");
|
||||
|
||||
static final ElementPattern<PsiElement> ANNOTATION_NAME =
|
||||
psiElement().withParents(PsiJavaCodeReferenceElement.class, PsiAnnotation.class).afterLeaf("@");
|
||||
|
||||
private static final ElementPattern<PsiElement> UNEXPECTED_REFERENCE_AFTER_DOT =
|
||||
psiElement().afterLeaf(".").insideStarting(psiExpressionStatement());
|
||||
private static final PsiNameValuePairPattern NAME_VALUE_PAIR =
|
||||
@@ -78,7 +75,7 @@ public class JavaCompletionContributor extends CompletionContributor {
|
||||
|
||||
public static final ElementPattern<PsiElement> IN_SWITCH_LABEL =
|
||||
psiElement().withSuperParent(2, psiElement(PsiExpressionList.class).withParent(psiElement(PsiSwitchLabelStatementBase.class).withSuperParent(2, PsiSwitchBlock.class)));
|
||||
private static final ElementPattern IN_ENUM_SWITCH_LABEL =
|
||||
private static final ElementPattern<PsiElement> IN_ENUM_SWITCH_LABEL =
|
||||
psiElement().withSuperParent(2, psiElement(PsiExpressionList.class).withParent(psiElement(PsiSwitchLabelStatementBase.class).withSuperParent(2,
|
||||
psiElement(PsiSwitchBlock.class).with(new PatternCondition<PsiSwitchBlock>("enumExpressionType") {
|
||||
@Override
|
||||
@@ -109,8 +106,8 @@ public class JavaCompletionContributor extends CompletionContributor {
|
||||
return new AndFilter(ElementClassFilter.CLASS, new NotFilter(new AssignableFromContextFilter()));
|
||||
}
|
||||
|
||||
if (ANNOTATION_NAME.accepts(position)) {
|
||||
return new AnnotationTypeFilter();
|
||||
if (getAnnotationNameIfInside(position) != null) {
|
||||
return new OrFilter(ElementClassFilter.PACKAGE, new AnnotationTypeFilter());
|
||||
}
|
||||
|
||||
if (JavaKeywordCompletion.isDeclarationStart(position) ||
|
||||
@@ -468,7 +465,7 @@ public class JavaCompletionContributor extends CompletionContributor {
|
||||
items.putValue(result1, new IndentingDecorator(TailTypeDecorator.withTail(element, switchLabelTail)));
|
||||
}
|
||||
else {
|
||||
final LookupItem item = element.as(LookupItem.CLASS_CONDITION_KEY);
|
||||
LookupItem<?> item = element.as(LookupItem.CLASS_CONDITION_KEY);
|
||||
if (originalFile instanceof PsiJavaCodeReferenceCodeFragment &&
|
||||
!((PsiJavaCodeReferenceCodeFragment)originalFile).isClassesAccepted() && item != null) {
|
||||
item.setTailType(TailType.NONE);
|
||||
@@ -814,9 +811,21 @@ public class JavaCompletionContributor extends CompletionContributor {
|
||||
context.setReplacementOffset(range.getEndOffset());
|
||||
}
|
||||
}
|
||||
|
||||
PsiJavaCodeReferenceElement ref = getAnnotationNameIfInside(file.findElementAt(context.getStartOffset()));
|
||||
if (ref != null) {
|
||||
context.setReplacementOffset(ref.getTextRange().getEndOffset());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static PsiJavaCodeReferenceElement getAnnotationNameIfInside(@Nullable PsiElement position) {
|
||||
PsiAnnotation anno = PsiTreeUtil.getParentOfType(position, PsiAnnotation.class);
|
||||
PsiJavaCodeReferenceElement ref = anno == null ? null : anno.getNameReferenceElement();
|
||||
return ref != null && PsiTreeUtil.isAncestor(ref, position, false) ? ref : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String customizeDummyIdentifier(@NotNull CompletionInitializationContext context, PsiFile file) {
|
||||
if (context.getCompletionType() != CompletionType.BASIC) return null;
|
||||
|
||||
@@ -4,8 +4,10 @@ final class MyModule {
|
||||
public static @interface Dependency { }
|
||||
}
|
||||
|
||||
class MyAnotherModule {}
|
||||
|
||||
final class SomeService {
|
||||
|
||||
SomeService(@My<caret>) {
|
||||
SomeService(@My<caret>.Inner) {
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,8 @@ final class MyModule {
|
||||
public static @interface Dependency { }
|
||||
}
|
||||
|
||||
class MyAnotherModule {}
|
||||
|
||||
final class SomeService {
|
||||
|
||||
SomeService(@MyModule.Dependency<caret>) {
|
||||
|
||||
+6
-1
@@ -995,7 +995,12 @@ public class ListUtils {
|
||||
|
||||
void testMethodParameterAnnotationClass() throws Throwable { doTest() }
|
||||
|
||||
void testInnerAnnotation() { doTest('\n') }
|
||||
void testInnerAnnotation() {
|
||||
configure()
|
||||
assert myFixture.lookupElementStrings == ['Dependency']
|
||||
type '\t'
|
||||
checkResult()
|
||||
}
|
||||
|
||||
void testPrimitiveCastOverwrite() throws Throwable { doTest() }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user