@NotNull
 private ElementFilter getDefaultFilter(PsiElement insertedElement) {
   return AFTER_THROW_NEW.accepts(insertedElement)
       ? new AssignableFromFilter("java.lang.Throwable")
       : IN_TYPE_PARAMETER.accepts(insertedElement)
           ? new ExcludeDeclaredFilter(new ClassFilter(PsiTypeParameter.class))
           : INSIDE_METHOD_THROWS_CLAUSE.accepts(insertedElement)
               ? new AnyInnerFilter(new AssignableFromFilter("java.lang.Throwable"))
               : getLocalFilter(insertedElement);
 }
 public static boolean isInsideParameterList(PsiElement position) {
   PsiElement prev = PsiTreeUtil.prevVisibleLeaf(position);
   PsiModifierList modifierList = PsiTreeUtil.getParentOfType(prev, PsiModifierList.class);
   if (modifierList != null) {
     if (PsiTreeUtil.isAncestor(modifierList, position, false)) {
       return false;
     }
     PsiElement parent = modifierList.getParent();
     return parent instanceof PsiParameterList
         || parent instanceof PsiParameter && parent.getParent() instanceof PsiParameterList;
   }
   return INSIDE_PARAMETER_LIST.accepts(position);
 }
  private static void addPrimitiveTypes(final Consumer<LookupElement> result, PsiElement position) {
    if (AFTER_DOT.accepts(position)) {
      return;
    }

    boolean afterNew =
        psiElement()
            .afterLeaf(
                psiElement()
                    .withText(PsiKeyword.NEW)
                    .andNot(psiElement().afterLeaf(PsiKeyword.THROW, ".")))
            .accepts(position);
    if (afterNew) {
      PsiElementFactory factory = JavaPsiFacade.getElementFactory(position.getProject());
      for (String primitiveType : PRIMITIVE_TYPES) {
        result.consume(
            PsiTypeLookupItem.createLookupItem(
                factory.createTypeFromText(primitiveType + "[]", null), null));
      }
      result.consume(
          PsiTypeLookupItem.createLookupItem(factory.createTypeFromText("void[]", null), null));
      return;
    }

    boolean inCast =
        psiElement()
            .afterLeaf(
                psiElement()
                    .withText("(")
                    .withParent(
                        psiElement(PsiParenthesizedExpression.class, PsiTypeCastExpression.class)))
            .accepts(position);

    boolean typeFragment =
        position.getContainingFile() instanceof PsiTypeCodeFragment
            && PsiTreeUtil.prevVisibleLeaf(position) == null;
    boolean declaration = DECLARATION_START.getValue().accepts(position);
    boolean expressionPosition = isExpressionPosition(position);
    boolean inGenerics =
        PsiTreeUtil.getParentOfType(position, PsiReferenceParameterList.class) != null;
    if (START_FOR.accepts(position)
        || isInsideParameterList(position)
        || inGenerics
        || VARIABLE_AFTER_FINAL.accepts(position)
        || inCast
        || declaration
        || typeFragment
        || expressionPosition
        || isStatementPosition(position)) {
      for (String primitiveType : PRIMITIVE_TYPES) {
        result.consume(createKeyword(position, primitiveType));
      }
    }
    if (declaration) {
      result.consume(
          new OverrideableSpace(
              createKeyword(position, PsiKeyword.VOID), TailType.HUMBLE_SPACE_BEFORE_WORD));
    } else if (typeFragment && ((PsiTypeCodeFragment) position.getContainingFile()).isVoidValid()) {
      result.consume(createKeyword(position, PsiKeyword.VOID));
    }
  }
  @Override
  public void fillCompletionVariants(
      final CompletionParameters parameters, final CompletionResultSet _result) {
    if (parameters.getCompletionType() != CompletionType.BASIC) {
      return;
    }

    final PsiElement position = parameters.getPosition();
    if (!isInJavaContext(position)) {
      return;
    }

    if (AFTER_NUMBER_LITERAL.accepts(position)
        || UNEXPECTED_REFERENCE_AFTER_DOT.accepts(position)) {
      _result.stopHere();
      return;
    }

    final CompletionResultSet result = JavaCompletionSorting.addJavaSorting(parameters, _result);

    if (ANNOTATION_ATTRIBUTE_NAME.accepts(position)
        && !JavaCompletionData.isAfterPrimitiveOrArrayType(position)) {
      JavaCompletionData.addExpectedTypeMembers(parameters, result);
      completeAnnotationAttributeName(result, position, parameters);
      result.stopHere();
      return;
    }

    final InheritorsHolder inheritors = new InheritorsHolder(position, result);
    if (JavaSmartCompletionContributor.IN_TYPE_ARGS.accepts(position)) {
      new TypeArgumentCompletionProvider(false, inheritors)
          .addCompletions(parameters, new ProcessingContext(), result);
    }

    PrefixMatcher matcher = result.getPrefixMatcher();
    if (JavaSmartCompletionContributor.AFTER_NEW.accepts(position)) {
      new JavaInheritorsGetter(ConstructorInsertHandler.BASIC_INSTANCE)
          .generateVariants(parameters, matcher, inheritors);
    }

    if (IMPORT_REFERENCE.accepts(position)) {
      result.addElement(LookupElementBuilder.create("*"));
    }

    addKeywords(parameters, result);

    Set<String> usedWords = addReferenceVariants(parameters, result, inheritors);

    if (psiElement().inside(PsiLiteralExpression.class).accepts(position)) {
      PsiReference reference = position.getContainingFile().findReferenceAt(parameters.getOffset());
      if (reference == null || reference.isSoft()) {
        WordCompletionContributor.addWordCompletionVariants(result, parameters, usedWords);
      }
    }

    JavaGenerateMemberCompletionContributor.fillCompletionVariants(parameters, result);

    addAllClasses(parameters, result, inheritors);

    final PsiElement parent = position.getParent();
    if (parent instanceof PsiReferenceExpression
        && !((PsiReferenceExpression) parent).isQualified()
        && parameters.isExtendedCompletion()
        && StringUtil.isNotEmpty(matcher.getPrefix())) {
      new JavaStaticMemberProcessor(parameters).processStaticMethodsGlobally(matcher, result);
    }
    result.stopHere();
  }