Remove element from autocomplete

In my plugin I want hide some fields from auto complete.
For example, I have:

class A {
     @Hide
     public int a;
     public int b;
}

and when I use it:

class B {
     void method() {
          A a = new A();
          a.          // in this place during the auto complete field "a" shouldn't be displayed, only b
     }
}

I try with CompletionContribution but it can only add some elements to view. Or am I mistaken?
If I could give filter for contributor, or something similar, it's would be nice.

6 comments

I inherited a JavaCompletionContributor and overrided his methods and added a filter.

0

Hi, can you give a simple filter example how to solve this assignment? E.g. We have names list, and should remove all which contains postfix 'Exclude'

0

I think this is wrong solution, but I didn't come up with another.
I added new class that extend JavaCompletionContributor (registred it in plugin.xml). (I place him before original javaContributor order="last, before legacy, before default, before javaClassName, before javaLegacy")
Then I rewrite "getReferenceFilter()" and (copy paste almost all methods from original class to my class)       chain:     fillCompletionVariants()->addReferenceVariants()->getReferenceFilter()

In getReferenceFilter I changed TrueFilter to my custom.


I think this is a very bad way, so if you find another, I'll be glad to know about it.

0
I added new class that extend JavaCompletionContributor

Can you attach code of your contributor and filter? I want to look at them, and try to find a better solution.

0

My current code was changed for other problems. And it can be confusing.


In addReferenceVariants(final CompletionParameters parameters, CompletionResultSet result, final InheritorsHolder inheritors) i change call JavaCompletionContributor.getReferenceFilter(position) to custom:

 
@Nullable
public static ElementFilter getReferenceFilter(PsiElement position) {
  ElementFilter filter = JavaCompletionContributor.getReferenceFilter(position);
  if (filter == TrueFilter.INSTANCE) {
    return SomeElementFilter.INSTANCE;              // replace filter
  
}
  return filter;
}


Where SomeElementFilter

 
final public static class SomeElementFilter implements ElementFilter {
  public static final ElementFilter INSTANCE = new SomeElementFilter();

  private SomeElementFilter() {}

  @Override
  public boolean isAcceptable
(Object element, @Nullable PsiElement context) {
// some other filter logic
  }

}

0

Please sign in to leave a comment.