// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.codeInsight.template.impl;

import com.intellij.codeInsight.completion.InsertionContext;
import com.intellij.codeInsight.template.Template;
import com.intellij.codeInsight.template.TemplateManager;
import com.intellij.openapi.util.text.StringUtil;
import org.jetbrains.annotations.NotNull;

public class LiveTemplateLookupElementImpl extends LiveTemplateLookupElement {
  private final TemplateImpl myTemplate;

  public LiveTemplateLookupElementImpl(@NotNull TemplateImpl template, boolean sudden) {
    super(template.getKey(), StringUtil.notNullize(template.getDescription()), sudden, LiveTemplateCompletionContributor.shouldShowAllTemplates());
    myTemplate = template;
  }

  @NotNull
  @Override
  public String getLookupString() {
    return myTemplate.getKey();
  }

  @NotNull
  public TemplateImpl getTemplate() {
    return myTemplate;
  }

  @Override
  public char getTemplateShortcut() {
    return TemplateSettings.getInstance().getShortcutChar(myTemplate);
  }

  @Override
  public void handleInsert(@NotNull InsertionContext context) {
    startTemplate(context, myTemplate);
  }

  public static void startTemplate(InsertionContext context, @NotNull Template template) {
    context.getDocument().deleteString(context.getStartOffset(), context.getTailOffset());
    context.setAddCompletionChar(false);
    TemplateManager.getInstance(context.getProject()).startTemplate(context.getEditor(), template);
  }
}

@@ -446,16 +446,43 @@
 tNull;%0A%0A
+import java.util.Objects;%0A%0A
 public c
@@ -1609,11 +1609,376 @@
 te);%0A  %7D
+%0A%0A  @Override%0A  public boolean equals(Object o) %7B%0A    if (this == o) return true;%0A    if (o == null %7C%7C getClass() != o.getClass()) return false;%0A    LiveTemplateLookupElementImpl element = (LiveTemplateLookupElementImpl)o;%0A    return Objects.equals(myTemplate, element.myTemplate);%0A  %7D%0A%0A  @Override%0A  public int hashCode() %7B%0A    return Objects.hash(myTemplate);%0A  %7D
 %0A%7D%0A

fix CWM-208, cleanup BackendCompletionHost.kt