Remove element from autocomplete

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

class A {
     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.


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


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'


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.

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.


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:

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() {}

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



Please sign in to leave a comment.