package jetbrains.mps.kotlin.editor;

/*Generated by MPS */

import jetbrains.mps.openapi.editor.menus.style.EditorMenuItemCustomizer;
import jetbrains.mps.openapi.editor.menus.style.EditorMenuItemStyle;
import jetbrains.mps.openapi.editor.menus.style.EditorMenuItemCustomizationContext;
import jetbrains.mps.editor.runtime.completion.CompletionMenuItemCustomizationContext;
import jetbrains.mps.editor.runtime.menus.EditorMenuItemCreatingConceptContextMatcher;
import org.jetbrains.mps.openapi.model.SNode;
import jetbrains.mps.editor.runtime.menus.EditorMenuItemCreatingCustomizationContext;
import org.jetbrains.mps.openapi.language.SContainmentLink;
import jetbrains.mps.editor.runtime.completion.CompletionItemInformation;
import org.jetbrains.mps.openapi.language.SInterfaceConcept;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;

public class FunctionCall_Priority implements EditorMenuItemCustomizer {

  @Override
  public void customize(EditorMenuItemStyle customization, EditorMenuItemCustomizationContext context) {
    if (context.get(CompletionMenuItemCustomizationContext.COMPLETION_ITEM_INFORMATION) == null) {
      return;
    }
    FunctionCall_PrioritySpecific customizer = new FunctionCall_PrioritySpecific();
    if (customizer.matches(context)) {
      customizer.customize(customization, context);
    }
  }

  private static class FunctionCall_PrioritySpecific implements EditorMenuItemCustomizer {

    public boolean matches(EditorMenuItemCustomizationContext context) {
      return new EditorMenuItemCreatingConceptContextMatcher(CONCEPTS.IFunctionCall$Sf).matchesContext(context) && getCompletionItemInformation(context) != null;
    }


    private SNode getParentNode(EditorMenuItemCustomizationContext context) {
      return context.get(EditorMenuItemCreatingCustomizationContext.PARENT_NODE);
    }
    private SNode getChild(EditorMenuItemCustomizationContext context) {
      return context.get(EditorMenuItemCreatingCustomizationContext.CURRENT_CHILD);
    }
    private SContainmentLink getLink(EditorMenuItemCustomizationContext context) {
      return context.get(EditorMenuItemCreatingCustomizationContext.CONTAINMENT_LINK);
    }
    private CompletionItemInformation getCompletionItemInformation(EditorMenuItemCustomizationContext context) {
      return context.get(CompletionMenuItemCustomizationContext.COMPLETION_ITEM_INFORMATION);
    }

    @Override
    public void customize(EditorMenuItemStyle style, EditorMenuItemCustomizationContext context) {
      customize_(getParentNode(context), getChild(context), getLink(context), style, getCompletionItemInformation(context));
    }
    private void customize_(SNode parentNode, SNode currentChild, SContainmentLink containmentLink, EditorMenuItemStyle style, CompletionItemInformation itemInformation) {
      CompletionPriorities.apply(CompletionPriorities.FUNCTION, itemInformation.getParameterObject(), parentNode, style);
    }
  }


  private static final class CONCEPTS {
    /*package*/ static final SInterfaceConcept IFunctionCall$Sf = MetaAdapterFactory.getInterfaceConcept(0x6b3888c1980244d8L, 0x8baff8e6c33ed689L, 0x5a442f44db6c8a2cL, "jetbrains.mps.kotlin.structure.IFunctionCall");
  }
}
