mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-84963 Disprefer annotations in autocomplete at places where they cannot be used
This commit is contained in:
@@ -93,7 +93,13 @@ public class PreferByKindWeigher extends LookupElementWeigher {
|
||||
assert annotation != null;
|
||||
PsiAnnotationOwner owner = annotation.getOwner();
|
||||
if (owner instanceof PsiModifierList || owner instanceof PsiTypeElement || owner instanceof PsiTypeParameter) {
|
||||
PsiElement member = owner instanceof PsiModifierList ? ((PsiElement)owner).getParent() : (PsiElement)owner;
|
||||
PsiElement member = (PsiElement)owner;
|
||||
if (member instanceof PsiModifierList) {
|
||||
member = member.getParent();
|
||||
}
|
||||
if (member instanceof PsiTypeElement && member.getParent() instanceof PsiMethod) {
|
||||
member = member.getParent();
|
||||
}
|
||||
final String[] elementTypeFields = PsiAnnotationImpl.getApplicableElementTypeFields(member);
|
||||
return new Condition<PsiClass>() {
|
||||
@Override
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
class Foo {
|
||||
@T<caret>
|
||||
public static void main(String[] args) {
|
||||
|
||||
}
|
||||
}
|
||||
+13
@@ -356,6 +356,19 @@ import java.lang.annotation.Target;
|
||||
checkPreferredItems 0, 'TMetaAnno', 'Target', 'TreeSelectionMode', 'TLocalAnno'
|
||||
}
|
||||
|
||||
public void testPreferApplicableAnnotationsMethod() throws Throwable {
|
||||
myFixture.addClass '''
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ElementType.TYPE})
|
||||
@interface TClassAnno {}
|
||||
|
||||
@Target({ElementType.METHOD})
|
||||
@interface TMethodAnno {}'''
|
||||
checkPreferredItems 0, 'TMethodAnno', 'TClassAnno'
|
||||
}
|
||||
|
||||
public void testJComponentAddNewWithStats() throws Throwable {
|
||||
final LookupImpl lookup = invokeCompletion("/../smartTypeSorting/JComponentAddNew.java");
|
||||
assertPreferredItems(0, "FooBean3", "JComponent", "Component");
|
||||
|
||||
Reference in New Issue
Block a user