IDEA-84963 Disprefer annotations in autocomplete at places where they cannot be used

This commit is contained in:
peter
2012-10-25 18:32:07 +02:00
parent 6a6c159af4
commit 0385ecc58a
3 changed files with 26 additions and 1 deletions
@@ -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
@@ -0,0 +1,6 @@
class Foo {
@T<caret>
public static void main(String[] args) {
}
}
@@ -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");