@Test public void insertHandler() { testHelper.getPsiClass( classes -> { PsiClass OneCls = classes.get(0); List<String> inserts = new ArrayList<>(1); TestCompletionResultSet mutate = new TestCompletionResultSet(); List<String> namesToReplace = new ArrayList<>(); namesToReplace.add("One"); ReplacingConsumer replacingConsumer = new ReplacingConsumer( namesToReplace, mutate, (context, item) -> inserts.add(item.getLookupString())); replacingConsumer.consume(createCompletionResultFor(OneCls)); mutate.elements.get(0).handleInsert(Mockito.mock(InsertionContext.class)); assertThat(inserts).hasSize(1); assertThat(inserts.get(0)).isEqualTo("One"); return true; }, "One.java"); }
@Override public void consume(CompletionResult completionResult) { LookupElement lookupElement = completionResult.getLookupElement(); result.passResult( Optional.ofNullable(lookupElement.getPsiElement()) .filter(PsiClass.class::isInstance) .map(psiClass -> ((PsiClass) psiClass).getQualifiedName()) .filter(replacedQualifiedNames::remove) .map( qualifiedName -> CompletionUtils.wrap( completionResult, SpecLookupElement.create(lookupElement, qualifiedName, insertHandler))) .orElse(completionResult)); }
ReplacingConsumer implements Consumer<CompletionResult> { @Override public void consume(CompletionResult completionResult) { LookupElement lookupElement = completionResult.getLookupElement(); result.passResult( Optional.ofNullable(lookupElement.getPsiElement()) .filter(PsiClass.class::isInstance) .map(psiClass -> ((PsiClass) psiClass).getQualifiedName()) .filter(replacedQualifiedNames::remove) .map( qualifiedName -> CompletionUtils.wrap( completionResult, SpecLookupElement.create(lookupElement, qualifiedName, insertHandler))) .orElse(completionResult)); } }
ReplacingConsumer implements Consumer<CompletionResult> { @Override public void consume(CompletionResult completionResult) { LookupElement lookupElement = completionResult.getLookupElement(); result.passResult( Optional.ofNullable(lookupElement.getPsiElement()) .filter(PsiClass.class::isInstance) .map(psiClass -> ((PsiClass) psiClass).getQualifiedName()) .filter(replacedQualifiedNames::remove) .map( qualifiedName -> CompletionUtils.wrap( completionResult, SpecLookupElement.create(lookupElement, qualifiedName, insertHandler))) .orElse(completionResult)); } ReplacingConsumer(
      Collection<String> replacedQualifiedNames,
      CompletionResultSet result,
      InsertHandler<LookupElement> insertHandler); }
ReplacingConsumer implements Consumer<CompletionResult> { @Override public void consume(CompletionResult completionResult) { LookupElement lookupElement = completionResult.getLookupElement(); result.passResult( Optional.ofNullable(lookupElement.getPsiElement()) .filter(PsiClass.class::isInstance) .map(psiClass -> ((PsiClass) psiClass).getQualifiedName()) .filter(replacedQualifiedNames::remove) .map( qualifiedName -> CompletionUtils.wrap( completionResult, SpecLookupElement.create(lookupElement, qualifiedName, insertHandler))) .orElse(completionResult)); } ReplacingConsumer(
      Collection<String> replacedQualifiedNames,
      CompletionResultSet result,
      InsertHandler<LookupElement> insertHandler); @Override void consume(CompletionResult completionResult); }
ReplacingConsumer implements Consumer<CompletionResult> { @Override public void consume(CompletionResult completionResult) { LookupElement lookupElement = completionResult.getLookupElement(); result.passResult( Optional.ofNullable(lookupElement.getPsiElement()) .filter(PsiClass.class::isInstance) .map(psiClass -> ((PsiClass) psiClass).getQualifiedName()) .filter(replacedQualifiedNames::remove) .map( qualifiedName -> CompletionUtils.wrap( completionResult, SpecLookupElement.create(lookupElement, qualifiedName, insertHandler))) .orElse(completionResult)); } ReplacingConsumer(
      Collection<String> replacedQualifiedNames,
      CompletionResultSet result,
      InsertHandler<LookupElement> insertHandler); @Override void consume(CompletionResult completionResult);  }